开发者

php start php script and continue

开发者 https://www.devze.com 2023-03-08 04:35 出处:网络
At the moment I have a line of code like this: system(\"/usr/bin/php myphpscript.php --param=\".val); Is there a way to make php not wait for the script to finish - and just move on instead?

At the moment I have a line of code like this:

system("/usr/bin/php myphpscript.php --param=".val);

Is there a way to make php not wait for the script to finish - and just move on instead?

It's a loop moving email, and the myphpscript.php is parsing the mails. And I don't wan't to wait for myphpscript.php to finish each time - just start it and move on!

UPDATE SOLUTION

Found the answer here:

http://www.php.net/manual/en/function.exec.php#101506

passthru("/usr/bin/php myphpscrip开发者_Python百科t.php --param=".val." >> /dev/null 2>&1 &");

Exp:

/dev/null

I needed to write to something else that STDOUT, else PHP will hang untill script finish. So I write to /dev/null instead.

2>&1

Redirecting errors to STDOUT

&

"Run in background" as mentioned in this thread.

Have a good day!

  • jack

  • jack


This should work

exec("/usr/bin/php myphpscript.php --param=".val . '&');


Throwing the background command to the end should le the script continue:

system("/usr/bin/php myphpscript.php --param=".val . "&");

I'd also add nohup just to be safe, since I think this sub-process might get killed when the parent php script finishes:

system("nohup /usr/bin/php myphpscript.php --param=".val . "&");

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号