From 34de8e43073c4c7eb4dbbbe5b21a7155be84634d Mon Sep 17 00:00:00 2001 From: "chris.boulton" Date: Sun, 27 Mar 2011 16:01:35 +1100 Subject: [PATCH] Add PIDFILE environment variable to write the PID of a single running worker out to a file --- resque.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/resque.php b/resque.php index 83b228b..d020622 100644 --- a/resque.php +++ b/resque.php @@ -5,7 +5,7 @@ if(empty($QUEUE)) { } $APP_INCLUDE = getenv('APP_INCLUDE'); -if(!$APP_INCLUDE) { +if($APP_INCLUDE) { if(!file_exists($APP_INCLUDE)) { die('APP_INCLUDE ('.$APP_INCLUDE.") does not exist.\n"); } @@ -66,6 +66,13 @@ else { $queues = explode(',', $QUEUE); $worker = new Resque_Worker($queues); $worker->logLevel = $logLevel; + + $PIDFILE = getenv('PIDFILE'); + if ($PIDFILE) { + file_put_contents($PIDFILE, getmypid()) or + die('Could not write PID information to ' . $PIDFILE); + } + fwrite(STDOUT, '*** Starting worker '.$worker."\n"); $worker->work($interval); }