Linode Forum Index Linode Forum
Linode Community Forums
 


Best way to run a PHP-CLI script forever.

Click here to go to the original topic

 
       Linode Forum Index -> Linux Tips, Tricks, Tutorials
Author Message
ferodynamics



Joined: 28 Mar 2010
Posts: 63
Location: Texas

Posted: Wed Mar 23, 2011 4:15 pm    Post subject: 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!
Back to top  
Guspaz



Joined: 26 May 2009
Posts: 1147
Location: Montreal, QC

Posted: Wed Mar 23, 2011 4:57 pm    Post subject:  

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.
Back to top  
ferodynamics



Joined: 28 Mar 2010
Posts: 63
Location: Texas

Posted: Wed Mar 23, 2011 9:23 pm    Post subject:  

Guspaz wrote: 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.
Back to top  
 
       Linode Forum Index -> Linux Tips, Tricks, Tutorials
Page 1 of 1