How do I run a PHP script as a service?
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:
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,
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.
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?
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 05:52 AM.|