-   Linux - Newbie (
-   -   How do I run a PHP script as a service? (

robbiemorgan 04-13-2005 08:24 AM

How do I run a PHP script as a service?
Hi all,

I have a PHP script which I need to run as a background process (daemon/service) on my Linux box. I figure it'd be best to set it up like any other service such as httpd and mysql, i.e. so I can go to /etc/init.d and type:

myscript start
myscript stop
myscript status
myscript restart


Is this the correct way to go about doing this, and if so, how do I do it - can I just copy and modify one of the other scripts?

Also, if I do it this way, is there some guarantee that the script will always be running (providing I add it to one of the rc*.d directories) - i.e. if it fails will the system automatically restart it?

Thanks in advance,


Technoslave 04-13-2005 11:34 AM

Yeah, you can just copy a simplistic startup script and use it for what you want, this is what I have done in the past.

As for restarting it if it dies, I do not believe that this is possible, the service is there just to start it up, not monitor it.

robbiemorgan 04-13-2005 01:21 PM

Thanks Technoslave. So, any thoughts on how to set up a basic service monitor? i.e. that attempts to restart the service on failure, and sends an e-mail alert?

Technoslave 04-13-2005 02:03 PM

I've done something in the past before via a 5 minute cron job, basically it's a simple script that does a ps for the process and if it didn't find it it would restart the app automatically ... this also made it so that I didn't need a startup script as at the next 5 minute mark it would auto-start the app anyway.

Other than that, I don't know ( b/c I haven't looked ) of any app out there that does that type of monitoring, if there is hopefully someone else will let us know.

All times are GMT -5. The time now is 12:26 AM.