PHP Worker Script Automatically Restart On Crash/Exit

1,094 views
Skip to first unread message

JustinSD

unread,
May 18, 2011, 4:51:55 PM5/18/11
to gearman
We are experimenting with gearman and PHP.

We are going to have our worker run on boot, by putting:

php -f /path/to/worker.php

In /etc/init.d/rc.local, but how do we protect our-self, and if for
some reason the script crashes and stops executing, have it
automatically restart. Is there a way to make it re-spawn itself?

Roger Hoover

unread,
May 18, 2011, 4:54:40 PM5/18/11
to gea...@googlegroups.com
You can use supervisord (http://supervisord.org/) for this.

John Ewart

unread,
May 18, 2011, 4:56:59 PM5/18/11
to gea...@googlegroups.com
Try looking into using something like supervisord (http://www.supervisord.org) or runit (http://smarden.org/runit/) to keep processes running. 

-John 

Shane Harter

unread,
May 18, 2011, 5:19:26 PM5/18/11
to gea...@googlegroups.com
supervisord is a good option.

I needed a native PHP mechanism to do this, so I wrote the feature into a basic daemon base class that we later opensourced: https://github.com/shaneharter/PHP-Daemon

Brian Moon

unread,
May 18, 2011, 6:58:25 PM5/18/11
to gea...@googlegroups.com, Shane Harter
I use GearmanManager to keep mine running. Just use supervisord or
something to keep that running and you are golden. There are init
scripts for some distros too.

https://github.com/brianlmoon/GearmanManager

Brian.
http://brian.moonspot.net

Reply all
Reply to author
Forward
0 new messages