PHP script running in background

All,

I am relatively new to this. I am trying to run a PHP process in the background but as soon as I launch the process it stops. Here is the basic command:

php script.php &

The idea is to leave this script running all day, even after I logout, in which case it seems like I will go with something like this:

nohup php script.php &

I am on Ubuntu and the script is opening a stream to the Twitter Streaming API.

Any ideas or suggestions would be appreciated. Thanks!

-et

5 Replies

If the script is run without putting it the background does it hold on to the shell and work?

php script.php

Any logging in to to see if it's erroring or terminating naturally?

Yes, it runs just fine in the foreground.

Try launching it this way:

nohup php -q /path/to/script.php < /dev/null &

Aha! That seems to work. At least it lets me run the script in the background while I am logged in. I don't think it stays running after I logout, so now I am going to figure out how to make that work.

Thanks so much,

-et

Ok, a little investigation revealed that it's indeed working exactly as I wanted - the process is running in the background and stays running even after I logout.

Excellent! Again, thanks for the help.

-et

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct