I’m trying to run a PHP script continually in the background via the command line in Linux. I have tried the command php filename.php & but it seems like the script execution terminates very quickly, while it should keep running until the process is terminated.
Any suggestions?
Are you sure the script doesn’t contain any errors? This is what normally makes "execution terminates very quickly".
First, append:
error_reporting(E_ALL); ini_set('display_errors', 1);at the top of your script to display any errors it may have, then you can use :
nohup php filename.php &OR
nohup php filename.php >/dev/null 2>&1 &You can also use:
ignore_user_abort(1);`set_time_limit(0);`
#Notes
The
phpand thefilename.phppaths may be provided as a full-path, instead ofphpandfilename.php, you can use/usr/bin/phpand/full/path/to/filename.php.Full Path is recommended to avoid file not found errors.