Best way to run a PHP-CLI script forever.

Best way to run a PHP-CLI script forever, even if I'm not logged in.

Last time I looked this up there were several options.

I would love to hear some suggestions.

Let's say I have a PHP script running in an endless loop on my Fedora VPS doing various things for me all day long and I want it to run forever, even when I'm not logged in.

Also: If the script dies for some reason, I would like to see the last moments of its death (say I'm drawing cool stuff to the terminal, not keeping an error log.)

Thanks!

2 Replies

The same way that any other program does? usleep() in a loop, or if you're waiting on a network socket, socket_select() with a null timeout (blocks forever until there's network activity to handle)?

The easiest way to run it in the background and see the output (other than redirecting stdout and stderr to a file) might be to use screen.

@Guspaz:

The same way that any other program does? usleep() in a loop, or if you're waiting on a network socket, socket_select() with a null timeout (blocks forever until there's network activity to handle)?

The easiest way to run it in the background and see the output (other than redirecting stdout and stderr to a file) might be to use screen.

Thanks Guspaz, I was thinking of "screen" but I couldn't remember the name.

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