April 22, 2012 Leave a comment
How to run php script in shell without waiting for an output allowing you to leave the script running in the background or even ending the terminal.
1. First create php script file e.g RunBashScript.php and add the following code:
exec(‘sh /[full path to bash script]/RunPhpScript.sh > /dev/null 2>&1 &’);
Save the file.
2. Next create bash script e.g RunPhpScript.sh and add the following:
/usr/bin/php -f /[full path to your actual php script]/ActualScriptToRun.php
Save that file.
3. To run your php script in the terminal type the following:
/usr/bin/php -f /[full path to bash script]/RunBashScript.php
Run “top” to see if PHP is running
To kill PHP simply run “pkill php”
Hope this helps someone!