How to run PHP in the background

I need to run some PHP scripts in the background, this script should still run while i log off my SSH session. I first try

php myscript.php &

It run in the background, but then when my SSH ends, the job will be also suspended.

After some research, finally, i found that i can use nohup command to do this job, it’s very simple

nohup php myscripts.php &

Remember to add & at the end of the script.

If you want to check if it’s actually runnning, use this commmand

jobs -l

Leave a Reply

Your email address will not be published. Required fields are marked *