Re: System_Daemon
| From: | Kevin van Zonneveld | Date: | Mon, 12 Jan 2009 15:56:08 +0000 |
| Subject: | Re: System_Daemon | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-29588@lists.php.net to get a copy of this message | ||
Thanks Bob!
I just did a write-up on System_Daemon that may interest you:
http://kevin.vanzonneveld.net/techblog/article/create_daemons_in_php/
.. it covers some additional caveats, tips & tricks. Cheers!
On Mon, Jan 12, 2009 at 4:29 PM, Robert T. Covell <rcovell@rolet.com> wrote:
> The daemons have been up and running since Wednesday of last week. So
> it seems that accessing the database was the issue.
>
> Just wanted to report back. Will let them run throughout the week and
> provide a final report.
>
> -Bob
>
>
>> -----Original Message-----
>> From: Robert T. Covell [mailto:rcovell@rolet.com]
>> Sent: Wednesday, January 07, 2009 3:18 PM
>> To: Kevin van Zonneveld
>> Cc: pear-general@lists.php.net
>> Subject: RE: [PEAR] System_Daemon
>>
>> Thank you for the pointers. I will try the db reconnect for every
> run.
>> They do seem to die at the same time, which could be during our backup
>> process (late at night).
>>
>> Will report back with findings...
>>
>> Thanks again..
>>
>> > -----Original Message-----
>> > From: vanzonneveld@gmail.com [mailto:vanzonneveld@gmail.com] On
> Behalf
>> Of
>> > Kevin van Zonneveld
>> > Sent: Wednesday, January 07, 2009 2:14 PM
>> > To: Robert T. Covell
>> > Cc: pear-general@lists.php.net
>> > Subject: Re: [PEAR] System_Daemon
>> >
>> > 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
>>
>> --
>> PEAR General Mailing List (http://pear.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Met vriendelijke groet / Kind regards,
Kevin van Zonneveld
http://kevin.vanzonneveld.net