[lug] Running a PHP script as a daemon

Jeff Schroeder jeff at zingstudios.net
Wed May 17 11:14:33 MDT 2006


Jason asked:

> Since this script needs to run
> all the time, what is the best way to handle that?  I'd like a
> solution that I can setup to start on system boot, and restart if for
> some reason PHP encounters a critical error and crashes (connection
> drop for example).

Why not just spawn it as a background process?

/usr/local/bin/myscript.php &

If you want it to launch at boot, you could either create a script 
in /etc/rc.d/init.d (or wherever-- I don't use CentOS so I don't know 
where the boot scripts are), or simply add it to /etc/rc.d/rc.local 
(again, whatever the CentOS equivalent is).

The advantage of the former-- placing it in the init.d area-- is that 
you could have "start", "stop", "restart", and "status" commands to 
control it.  But it would require you to write a shell script to manage 
that, whereas just adding the one-liner to rc.local is quick and dirty.

HTH,
Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20060517/e54475d1/attachment.pgp>


More information about the LUG mailing list