6

I have a daemon written in PHP. I use the following command to call the daemon

php dojobs.php

when I call that command, the daemon runs infinitely because the file dojobs.php has the following code

while(true)
{
   code here
}

I have the following questions:

  • How do I use Monit (on a CENTOS linux 5.5) server to monitor this daemon and restart it if it has failed?
  • I have the following code inside the daemon:

    exec('nohup sendMail.php > /dev/null 2>&1 & echo $!';, $op);

(how do I make sure the nohup command above works correctly and that the sendMail.php file actually does its job? The sendMail.php is not a daemon. It sends an email and then quits.)

Thank you so much.

1 Answer 1

2

Not familiar with Monit, so can't help you with that. But instead of calling exec() you can use the Process Control (pcntl_*()) extension to fork separate processes and wait for them to return a status code to the parent process, in order for it to know if the job has been successfuly completed or not.

2
  • the problem is my daemon is doing a lot of things. So it can't be waiting for processes.
    – user816604
    Dec 8, 2011 at 17:39
  • I don't mean wait like blocking the rest of the process - it's an endless loop, so you can periodically poll for return statuses.
    – Narf
    Dec 8, 2011 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.