phpdaemonbeanstalkdpheanstalk

Php daemon process crashing frequently


We are using beanstalkd to run receiving jobs from client, with php and using pheanstalk as php agent. we running a worker as php system daemon and keep monitoring using monit.

But it keeps restarting in a once in a day frequency. After observing issue it is confirm that no code side errors. So what are the chances?


Solution

  • PHP isn't designed as a long running process, and so restarting the script occasionally is probably a useful thing to do anyway - particularly if the clean exit is under your control.

    For example, you could run 50/100/1000 jobs in a loop, and then exit the script for it to be automatically restarted. Wrapping the call to the script in a fairly simple shell script can check a return value and then either restart immediately, or slow things down a little if there may be a problem.

    Reasons why a script can suddenly fail are many and various. A memory leak can force the OS to kill the process, an error might throw an uncaught exception, or other such fatal error, or something external to the script might cause a failure.

    The hard part of background workers for queues is dealing with the (potential) problems that can stop the script from working all the time. Verbose logs can help a lot in trying to track down such issues.