vcv Posted April 28, 2008 Share Posted April 28, 2008 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 Link to comment https://forums.phpfreaks.com/topic/103245-solved-run-external-program-and-not-wait-for-its-completion/ Share on other sites More sharing options...
dptr1988 Posted April 28, 2008 Share Posted April 28, 2008 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. Link to comment https://forums.phpfreaks.com/topic/103245-solved-run-external-program-and-not-wait-for-its-completion/#findComment-528863 Share on other sites More sharing options...
effigy Posted April 28, 2008 Share Posted April 28, 2008 pcntl_fork Link to comment https://forums.phpfreaks.com/topic/103245-solved-run-external-program-and-not-wait-for-its-completion/#findComment-528871 Share on other sites More sharing options...
dptr1988 Posted April 28, 2008 Share Posted April 28, 2008 pcntl_fork will fork the running PHP script. I think that he is wanting to run a seperate program. Link to comment https://forums.phpfreaks.com/topic/103245-solved-run-external-program-and-not-wait-for-its-completion/#findComment-528907 Share on other sites More sharing options...
vcv Posted April 28, 2008 Author Share Posted April 28, 2008 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! Link to comment https://forums.phpfreaks.com/topic/103245-solved-run-external-program-and-not-wait-for-its-completion/#findComment-529084 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.