Saturday, September 12, 2009

Starting another script

I have a PHP script that customers would use to start a process. The process was time-intensive, so I had it start another script in the background. It was important that the customer did not have to wait until the long process ended. After trying a few things, I found a forum that gave me my solution (sorry, can't find where it is anymore). This starts a PHP script in the background from within another PHP script:
shell_exec('php /public_html/accountname/longProcess.php > /dev/null 2>/dev/null &');

Simply replace the script name with our own and it should work (note: not sure if the whole path is required). What this does is force the standard output and error output to be discarded and the final ampersand causes it all to be run in the background.

No comments: