Re: System_Daemon

From: Date: Wed, 07 Jan 2009 20:13:34 +0000
Subject: Re: System_Daemon
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-29569@lists.php.net to get a copy of this message
Hello Bob, On Wed, Jan 7, 2009 at 7:15 PM, Robert T. Covell <rcovell@rolet.com> wrote: > We have developed four daemons using System_Daemon (0.50). All of them > run fine for an undetermined amount of time and then just disappear. > The pid file is still present but the process is gone. There are no > error messages in the log files either. > > Each daemon does perform checks against a database to see if anything > needs to be processed. Do we need to recycle the connection every so > often? I am the author of System_Daemon, and I've experienced something similar. In my case, I had a persistent mysql connection, but everytime the database server did a backup, it locked up; eventually causing my daemon to die because it could not execute any query, for way too long. The uptime of a daemon should not depend on a mysql connection, so one solution would be to reconnect every run (a cronjob would have done the same), and/or have good error-handling of course. But this may ,or may not be the cause of your problem. Generally to troubleshoot you could: 1. Save PHP Errors. Create your own error-handler with set_error_handler and have it log php errors. This is a good idea anyway, because when creating daemon, you have to realize that all STDIO & STDERR messages are basically lost. And occasionally they will tell you very important things. To test if your log successfully accepts php errors you can use trigger_error. 2. Not daemonize your script Run your normal code, just don't detach it from your session. This way you'll be able see exactly what's causing it's crash, optionally use 'screen' if for some reason you can't keep your terminal open that long. With screen you can always reconnect to a session and see what happened. To conditionally daemonize a script, the logparser example implements the '--no-daemon' argument , you could take a look at that. Or quick&dirty: comment the System_Daemon::start() statement. 3. Save timestamps Do it in your while() to find out when the daemon last reported to be alive, maybe there's a pattern. If all your four daemons die at the same time: my money would definitely be on your database. file_put_contents('/tmp/mydaemon_alive', date('r')); And then there is is 'monit', which can kick-start any malfunctioning or crashing daemon. This is not the way to solve your problem, but can be an additional safetynet for mission critical daemons. -- Met vriendelijke groet / Kind regards, Kevin van Zonneveld http://kevin.vanzonneveld.net

« previous php.pear.general (#29569) next »