Skip to content

Commit c928347

Browse files
authored
Merge pull request chrisboulton#299 from chrisboulton/fork-return
Return false if the fork function is unavailable
2 parents e684d19 + eba6ef5 commit c928347

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

bin/resque

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ if(!empty($PREFIX)) {
9696
if($count > 1) {
9797
for($i = 0; $i < $count; ++$i) {
9898
$pid = Resque::fork();
99-
if($pid == -1) {
99+
if($pid === false || pid === -1) {
100100
$logger->log(Psr\Log\LogLevel::EMERGENCY, 'Could not fork worker {count}', array('count' => $i));
101101
die();
102102
}

lib/Resque.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ public static function redis()
7272
*
7373
* Will close connection to Redis before forking.
7474
*
75-
* @return int Return vars as per pcntl_fork()
75+
* @return int Return vars as per pcntl_fork(). False if pcntl_fork is unavailable
7676
*/
7777
public static function fork()
7878
{
7979
if(!function_exists('pcntl_fork')) {
80-
return -1;
80+
return false;
8181
}
8282

8383
// Close the connection to Redis before forking.
@@ -281,12 +281,12 @@ private static function removeItems($queue, $items = Array())
281281
$originalQueue = 'queue:'. $queue;
282282
$tempQueue = $originalQueue. ':temp:'. time();
283283
$requeueQueue = $tempQueue. ':requeue';
284-
284+
285285
// move each item from original queue to temp queue and process it
286286
$finished = false;
287287
while (!$finished) {
288288
$string = self::redis()->rpoplpush($originalQueue, self::redis()->getPrefix() . $tempQueue);
289-
289+
290290
if (!empty($string)) {
291291
if(self::matchItem($string, $items)) {
292292
self::redis()->rpop($tempQueue);
@@ -311,7 +311,7 @@ private static function removeItems($queue, $items = Array())
311311
// remove temp queue and requeue queue
312312
self::redis()->del($requeueQueue);
313313
self::redis()->del($tempQueue);
314-
314+
315315
return $counter;
316316
}
317317

@@ -377,4 +377,3 @@ public static function generateJobId()
377377
return md5(uniqid('', true));
378378
}
379379
}
380-

0 commit comments

Comments
 (0)