Run PHP scripts in background on Linux

To run a PHP script in background from command line and keep it running even if you exit the terminal, use following syntax:

nohup php script.php < /dev/null &

nohup‘┬áis a POSIX command to ignore the HUP (hangup) signal, enabling the command to keep running after the user who issues the command has logged out.

In Unix-like operating systems, ‘/dev/null‘ or the null device is a special file that discards all data written to it.

‘&’ is to send the process in the background and return the command line prompt.

Leave a Reply

Your email address will not be published. Please enter your name, email and a comment.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">