Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to configure my CentOS VPS to continually check to make sure that a php script is running? Currently I'm using the screen php method which works fine, but if it gets terminated somehow, how can I start it backup?

I tried adding the command to /etc/rc.d/rc.local, however this morning I checked, and the script wasn't running.

share|improve this question

This task is well suited to a process monitor like Monit.

The monitoring configuration will be made much easier with Monit if your PHP process produces a PID file. An article describing how to use Monit to check and start PHP processes is available here.

share|improve this answer
This link seems to be dead now. – Gaurav Gupta Apr 28 '14 at 6:41
@GauravGupta can usually help you out.*/‌​on.htm – ceejayoz Apr 28 '14 at 13:57
True, already checked that. "Wayback Machine doesn't have that page archived." – Gaurav Gupta Apr 29 '14 at 4:25
@GauravGupta It works fine. SO's adding a space in the URL though - doesn't like the *. – ceejayoz Apr 29 '14 at 5:24

You can write a checking script that parses the output of the ps command, looking for your php instance. If it exists, then your script should silently exit; if it does not, then your script should launch your php program, and then write a message to stdout warning that the process was dead and had to be restarted.

Then, add your checking script to your crontab (e.g.)
*/5 * * * * /path/to/

In this example, your checking script runs every 5 minutes. If the php process is dead and your checking script relaunches it, then it will also output the formentioned message which will be emailed to you (as an alert).

share|improve this answer

This task is well suited for some outside monitoring like AlertFox, Pingdom, Monitis,... (all these have free plans).

The approach is always the same: you create a PHP page that checks that the PHO script is running, and the monitoring service calls it periodically:

share|improve this answer

you can use supervisord for this purpose. It is a python application but very simple to setup. Supervisord provides a auto restart directive in its config which will restart the script is case it dies.

you can read more about it on

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.