Jump to content

[SOLVED] Run external program and not wait for its completion


vcv

Recommended Posts

hello all, I have a problem that google has been unable to solve for me. I need a php script to run an external program and simply continue execution without waiting for its completion. Currently i am calling "system($cmd);" where that then runs a java program to create and send an xmlrpc request to the cluster that then performs calculations for at least an hour. What I would like is it to just call $cmd and not bother waitiing on it. thank you

If your server is running linux ( it better be!! ) you can add this char '&' at the end of your command line and it will run the task in the background.

 

Also, remember to redirect all outputs to a log file or /dev/null or else the PHP script will have to wait for the programs output.

thank you both for your replies. I had already tried the & but didnt route the output to /dev/null and doing so made it work like a charm :) . So for future posterity, my solution is:

system($cmd."  > /dev/null 2>&1 &");

 

I didnt try the fork but im sure that could work if i just didnt wait for the child. Thank you very much for ya'lls help!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.