A simple solution is
nohup php script.php &
So you run script in background and disconnect the process from the terminal. If it doesn't help, try disown
command after it. There is a good answer with detailed explanation of differences between these commands.
To get full control of your script, a good choice would be a System V
init script. There is a template at https://github.com/fhd/init-script-template, which you can use.
Copy template to /etc/init.d
directory and rename it. In template you need to change variables:
dir="/your/working/directory"
cmd="nohup php script.php"
user="your user"
Doing that you will be able to control your script by
/etc/init.d/your_script start
/etc/init.d/your_script stop
Make sure you have permissions to write in /var/log/
and /var/run/
, or run script as sudo
(leave user=""
empty)