1

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 myphpscript.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

jack
  • 1,317
  • 1
  • 14
  • 21

2 Answers2

0

This should work

exec("/usr/bin/php myphpscript.php --param=".val . '&');
KingCrunch
  • 128,817
  • 21
  • 151
  • 173
  • This solution+nohup gives me "nohup: redirecting stderr to stdout" + my subscript output. Without nohup, just give me subscript output. (In my terminal). – jack May 23 '11 at 10:30
0

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 . "&");

opsguy
  • 1,781
  • 1
  • 12
  • 11
  • I've added your changes, but if I run the script through a terminal - the script is still waiting for myphpscript.php to be done. And then my IMAP connection will time out. Is there a way to make the main script move on after starting the subscript? – jack May 23 '11 at 10:28