Jump to content

run php-cli script with socket management from another php script with feedback


eki33

Recommended Posts

Hello,

 

I stored a fsockopen function in a separate "called.php" file, in order to run it as another thread when it needs.

The called script should return results to the "master.php" script.

I'm able to run the script to get the socket working, and I'm able to get results from the called script. I tried for hours but I can't do the twice both  :(

 

My master.php script (with socket working):

 

<?php
$command = "(/mnt/opt/www/called.php $_SERVER[REMOTE_ADDR] &) > /dev/null";
$result = exec($command);
echo ("result = $result\r\n");
?>

 

and my called.php script

#!/mnt/opt/usr/bin/php-cli -q
<?php
$device = $_SERVER['argv'][1];
$port = "8080";
$fp = fsockopen($device, $port, $errno, $errstr, 5);
fwrite($fp, "test");
fclose($fp);
echo ("normal end of the called.php script");
?>

 

In the master script, if I use

$command = "(/mnt/opt/www/called.php $_SERVER[REMOTE_ADDR] &) > /dev/null";

the socket works, but I have nothing in $result

(note also that I don't anderstand why the ( ... &) are needed!?)

 

and if I use

$command = "/mnt/opt/www/called.php $_SERVER[REMOTE_ADDR]";

I have the correct text "normal end of the called.php script" in $result but the socket connection is not performed (no errors in php logs)

 

Could you help me to find a way to let's work the two features correctly together?

Thank you.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.