cocur / background-process

Start processes in the background that continue running when the PHP process exists.
MIT License
294 stars 60 forks source link

How do I send the parameter? #25

Closed emresaracoglu closed 6 years ago

emresaracoglu commented 6 years ago

Hi,

$firstWords = "Hello World";
$process = new BackgroundProcess('/usr/local/bin/php /home/[...]/test.php');

test.php:

echo "This is first words: ".$firstWords; // print: "This is first words: ";

The strings do not reach the other page. I wanted to use argv in Cron for this. (link) it still did not work.

what is your idea on this issue? Thanks

florianeckerstorfer commented 6 years ago

You need to pass the $firstWords variable to your script. Then use $argv[1] to read the content.

$firstWords = "Hello World";
$process = new BackgroundProcess('/usr/local/bin/php /home/[...]/test.php "'.$firstWords.'"');
florianeckerstorfer commented 6 years ago

A tip for debugging this. echo the string you pass into new BackgroundProcess, copy it and execute it in a Terminal window. If it works in the Terminal it should work in BackgroundProcess.

emresaracoglu commented 6 years ago

Yes, That's all! This script will make my job really easy, thank you for this script and answer @florianeckerstorfer Have a nice day.