PHP CLI script running in the background on Ubuntu

For a php script to run on a server in the background after closing ssh connection, it needs to be started the following way:

nohup php -q /path/to/your/daemon.php < /dev/null &
  • nohup (no hung-up) enables the script to keep running after the ssh connction is closed,
  • the -q parameter prevents php from outputting any headers that would normally output for a HTTP connection,
  • < /dev/nul (the null device) is a workaround as php cli on ubuntu seems to expect some input
  • & - the ampersand makes the script in the background

Comments

I'd vetnrue that this article

I'd vetnrue that this article has saved me more time than any other.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.

More information about formatting options

7 + 3 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.