From a8a7db51ca08e38667ed11ed4773aaedcddd3496 Mon Sep 17 00:00:00 2001 From: scragg0x Date: Fri, 7 Sep 2012 13:36:15 -0500 Subject: [PATCH 01/37] Disable autoload for the class_exists func MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I ran into an autoload problem because of this class_exists function. So I set the second arg to false to prevent it from calling __autoload.   It doesn't make sense to try (to autoload) anyway because it's going to declare a skeleton if the class doesn't exist. --- lib/Redisent/Redisent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Redisent/Redisent.php b/lib/Redisent/Redisent.php index 1580b89..4b480f6 100644 --- a/lib/Redisent/Redisent.php +++ b/lib/Redisent/Redisent.php @@ -13,7 +13,7 @@ define('CRLF', sprintf('%s%s', chr(13), chr(10))); * Wraps native Redis errors in friendlier PHP exceptions * Only declared if class doesn't already exist to ensure compatibility with php-redis */ -if (! class_exists('RedisException')) { +if (! class_exists('RedisException', false)) { class RedisException extends Exception { } } From c6bd34d00d1b5e479f2340f9bcc0a5f2e85edf74 Mon Sep 17 00:00:00 2001 From: Chris Boulton Date: Sat, 13 Oct 2012 17:52:09 +1100 Subject: [PATCH 02/37] update changelog in prep for 1.2 --- CHANGELOG.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f2d66b..9e97469 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 1.2 (Unreleased) ## +## 1.2 (2012-10-13) ## * Allow alternate redis database to be selected when calling setBackend by supplying a second argument (patrickbajao) * Use `require_once` when including php-resque after the app has been included in the sample resque.php to prevent include conflicts (andrewjshults) @@ -10,7 +10,16 @@ * Fix lost jobs when there is more than one worker process started by the same parent process (salimane) * Move include for resque before APP_INCLUDE is loaded in, so that way resque is available for the app * Avoid working with dirty worker IDs (salimane) - +* Allow UNIX socket to be passed to Resque when connecting to Redis (pedroarnal) +* Fix typographical errors in PHP docblocks (chaitanyakuber) +* Set the queue name on job instances when jobs are executed (chaitanyakuber) +* Fix and add tests for Resque_Event::stopListening (ebernhardson) +* Documentation cleanup (maetl) +* Pass queue name to afterEvent callback +* Only declare RedisException if it doesn't already exist (Matt Heath) +* Add support for Composer +* Fix missing and incorrect paths for Resque and Resque_Job_Status classes in demo (jjfrey) +* Disable autoload for the RedisException class_exists call (scragg0x) ## 1.1 (2011-03-27) ## From c908109a746f03abdb7a23a54dcf2e17694ca28d Mon Sep 17 00:00:00 2001 From: Chris Boulton Date: Sat, 13 Oct 2012 17:55:41 +1100 Subject: [PATCH 03/37] Remove silly copyright line in docblock comments, update email address, remove copyright year because it is boring to maintain --- LICENSE | 2 +- lib/Resque.php | 3 +-- lib/Resque/Event.php | 3 +-- lib/Resque/Exception.php | 3 +-- lib/Resque/Failure.php | 3 +-- lib/Resque/Failure/Interface.php | 3 +-- lib/Resque/Failure/Redis.php | 3 +-- lib/Resque/Job.php | 3 +-- lib/Resque/Job/DirtyExitException.php | 3 +-- lib/Resque/Job/DontPerform.php | 3 +-- lib/Resque/Job/Status.php | 3 +-- lib/Resque/Redis.php | 3 +-- lib/Resque/RedisCluster.php | 3 +-- lib/Resque/Stat.php | 3 +-- lib/Resque/Worker.php | 3 +-- test/Resque/Tests/EventTest.php | 3 +-- test/Resque/Tests/JobStatusTest.php | 3 +-- test/Resque/Tests/JobTest.php | 3 +-- test/Resque/Tests/StatTest.php | 3 +-- test/Resque/Tests/TestCase.php | 3 +-- test/Resque/Tests/WorkerTest.php | 3 +-- test/Resque/Tests/bootstrap.php | 3 +-- 22 files changed, 22 insertions(+), 43 deletions(-) diff --git a/LICENSE b/LICENSE index 6513591..a796ebf 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -(c) 2010 Chris Boulton +(c) Chris Boulton Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/lib/Resque.php b/lib/Resque.php index 9bc8143..5362b5b 100644 --- a/lib/Resque.php +++ b/lib/Resque.php @@ -6,8 +6,7 @@ require_once dirname(__FILE__) . '/Resque/Exception.php'; * Base Resque class. * * @package Resque - * @author Chris Boulton - * @copyright (c) 2010 Chris Boulton + * @author Chris Boulton * @license http://www.opensource.org/licenses/mit-license.php */ class Resque diff --git a/lib/Resque/Event.php b/lib/Resque/Event.php index 930c067..20072ff 100644 --- a/lib/Resque/Event.php +++ b/lib/Resque/Event.php @@ -3,8 +3,7 @@ * Resque event/plugin system class * * @package Resque/Event - * @author Chris Boulton - * @copyright (c) 2010 Chris Boulton + * @author Chris Boulton * @license http://www.opensource.org/licenses/mit-license.php */ class Resque_Event diff --git a/lib/Resque/Exception.php b/lib/Resque/Exception.php index b288bf4..60cca86 100644 --- a/lib/Resque/Exception.php +++ b/lib/Resque/Exception.php @@ -3,8 +3,7 @@ * Resque exception. * * @package Resque - * @author Chris Boulton - * @copyright (c) 2010 Chris Boulton + * @author Chris Boulton * @license http://www.opensource.org/licenses/mit-license.php */ class Resque_Exception extends Exception diff --git a/lib/Resque/Failure.php b/lib/Resque/Failure.php index 9f6d89a..e0c28a3 100644 --- a/lib/Resque/Failure.php +++ b/lib/Resque/Failure.php @@ -5,8 +5,7 @@ require_once dirname(__FILE__) . '/Failure/Interface.php'; * Failed Resque job. * * @package Resque/Failure - * @author Chris Boulton - * @copyright (c) 2010 Chris Boulton + * @author Chris Boulton * @license http://www.opensource.org/licenses/mit-license.php */ class Resque_Failure diff --git a/lib/Resque/Failure/Interface.php b/lib/Resque/Failure/Interface.php index 863cd0b..b7e5bc8 100644 --- a/lib/Resque/Failure/Interface.php +++ b/lib/Resque/Failure/Interface.php @@ -3,8 +3,7 @@ * Interface that all failure backends should implement. * * @package Resque/Failure - * @author Chris Boulton - * @copyright (c) 2010 Chris Boulton + * @author Chris Boulton * @license http://www.opensource.org/licenses/mit-license.php */ interface Resque_Failure_Interface diff --git a/lib/Resque/Failure/Redis.php b/lib/Resque/Failure/Redis.php index c81bfc2..cfac5b6 100644 --- a/lib/Resque/Failure/Redis.php +++ b/lib/Resque/Failure/Redis.php @@ -3,8 +3,7 @@ * Redis backend for storing failed Resque jobs. * * @package Resque/Failure - * @author Chris Boulton - * @copyright (c) 2010 Chris Boulton + * @author Chris Boulton * @license http://www.opensource.org/licenses/mit-license.php */ diff --git a/lib/Resque/Job.php b/lib/Resque/Job.php index 0d275a1..661bd3c 100755 --- a/lib/Resque/Job.php +++ b/lib/Resque/Job.php @@ -7,8 +7,7 @@ require_once dirname(__FILE__) . '/Job/DontPerform.php'; * Resque job. * * @package Resque/Job - * @author Chris Boulton - * @copyright (c) 2010 Chris Boulton + * @author Chris Boulton * @license http://www.opensource.org/licenses/mit-license.php */ class Resque_Job diff --git a/lib/Resque/Job/DirtyExitException.php b/lib/Resque/Job/DirtyExitException.php index b69413a..108e061 100644 --- a/lib/Resque/Job/DirtyExitException.php +++ b/lib/Resque/Job/DirtyExitException.php @@ -3,8 +3,7 @@ * Runtime exception class for a job that does not exit cleanly. * * @package Resque/Job - * @author Chris Boulton - * @copyright (c) 2010 Chris Boulton + * @author Chris Boulton * @license http://www.opensource.org/licenses/mit-license.php */ class Resque_Job_DirtyExitException extends RuntimeException diff --git a/lib/Resque/Job/DontPerform.php b/lib/Resque/Job/DontPerform.php index 91d5c70..553327f 100644 --- a/lib/Resque/Job/DontPerform.php +++ b/lib/Resque/Job/DontPerform.php @@ -3,8 +3,7 @@ * Exception to be thrown if a job should not be performed/run. * * @package Resque/Job - * @author Chris Boulton - * @copyright (c) 2010 Chris Boulton + * @author Chris Boulton * @license http://www.opensource.org/licenses/mit-license.php */ class Resque_Job_DontPerform extends Exception diff --git a/lib/Resque/Job/Status.php b/lib/Resque/Job/Status.php index e1554b0..ffa351b 100644 --- a/lib/Resque/Job/Status.php +++ b/lib/Resque/Job/Status.php @@ -3,8 +3,7 @@ * Status tracker/information for a job. * * @package Resque/Job - * @author Chris Boulton - * @copyright (c) 2010 Chris Boulton + * @author Chris Boulton * @license http://www.opensource.org/licenses/mit-license.php */ class Resque_Job_Status diff --git a/lib/Resque/Redis.php b/lib/Resque/Redis.php index b6d7522..053f2f9 100644 --- a/lib/Resque/Redis.php +++ b/lib/Resque/Redis.php @@ -10,8 +10,7 @@ if(!class_exists('Redisent', false)) { * redis. Essentially adds namespace support to Redisent. * * @package Resque/Redis - * @author Chris Boulton - * @copyright (c) 2010 Chris Boulton + * @author Chris Boulton * @license http://www.opensource.org/licenses/mit-license.php */ class Resque_Redis extends Redisent diff --git a/lib/Resque/RedisCluster.php b/lib/Resque/RedisCluster.php index 39c3f5c..100bdb7 100644 --- a/lib/Resque/RedisCluster.php +++ b/lib/Resque/RedisCluster.php @@ -10,8 +10,7 @@ if(!class_exists('RedisentCluster', false)) { * redis. Essentially adds namespace support to Redisent. * * @package Resque/Redis - * @author Chris Boulton - * @copyright (c) 2010 Chris Boulton + * @author Chris Boulton * @license http://www.opensource.org/licenses/mit-license.php */ class Resque_RedisCluster extends RedisentCluster diff --git a/lib/Resque/Stat.php b/lib/Resque/Stat.php index 2805376..bc00c63 100644 --- a/lib/Resque/Stat.php +++ b/lib/Resque/Stat.php @@ -3,8 +3,7 @@ * Resque statistic management (jobs processed, failed, etc) * * @package Resque/Stat - * @author Chris Boulton - * @copyright (c) 2010 Chris Boulton + * @author Chris Boulton * @license http://www.opensource.org/licenses/mit-license.php */ class Resque_Stat diff --git a/lib/Resque/Worker.php b/lib/Resque/Worker.php index 31f2f3c..5aa1ccd 100644 --- a/lib/Resque/Worker.php +++ b/lib/Resque/Worker.php @@ -9,8 +9,7 @@ require_once dirname(__FILE__) . '/Job/DirtyExitException.php'; * off the queues, running them and handling the result. * * @package Resque/Worker - * @author Chris Boulton - * @copyright (c) 2010 Chris Boulton + * @author Chris Boulton * @license http://www.opensource.org/licenses/mit-license.php */ class Resque_Worker diff --git a/test/Resque/Tests/EventTest.php b/test/Resque/Tests/EventTest.php index 0bf5ee9..f53f2eb 100644 --- a/test/Resque/Tests/EventTest.php +++ b/test/Resque/Tests/EventTest.php @@ -5,8 +5,7 @@ require_once dirname(__FILE__) . '/bootstrap.php'; * Resque_Event tests. * * @package Resque/Tests - * @author Chris Boulton - * @copyright (c) 2010 Chris Boulton + * @author Chris Boulton * @license http://www.opensource.org/licenses/mit-license.php */ class Resque_Tests_EventTest extends Resque_Tests_TestCase diff --git a/test/Resque/Tests/JobStatusTest.php b/test/Resque/Tests/JobStatusTest.php index 5f0fd0f..61f09b1 100644 --- a/test/Resque/Tests/JobStatusTest.php +++ b/test/Resque/Tests/JobStatusTest.php @@ -5,8 +5,7 @@ require_once dirname(__FILE__) . '/bootstrap.php'; * Resque_Job_Status tests. * * @package Resque/Tests - * @author Chris Boulton - * @copyright (c) 2010 Chris Boulton + * @author Chris Boulton * @license http://www.opensource.org/licenses/mit-license.php */ class Resque_Tests_JobStatusTest extends Resque_Tests_TestCase diff --git a/test/Resque/Tests/JobTest.php b/test/Resque/Tests/JobTest.php index 3102291..572c51b 100644 --- a/test/Resque/Tests/JobTest.php +++ b/test/Resque/Tests/JobTest.php @@ -5,8 +5,7 @@ require_once dirname(__FILE__) . '/bootstrap.php'; * Resque_Job tests. * * @package Resque/Tests - * @author Chris Boulton - * @copyright (c) 2010 Chris Boulton + * @author Chris Boulton * @license http://www.opensource.org/licenses/mit-license.php */ class Resque_Tests_JobTest extends Resque_Tests_TestCase diff --git a/test/Resque/Tests/StatTest.php b/test/Resque/Tests/StatTest.php index 6404794..167633c 100644 --- a/test/Resque/Tests/StatTest.php +++ b/test/Resque/Tests/StatTest.php @@ -5,8 +5,7 @@ require_once dirname(__FILE__) . '/bootstrap.php'; * Resque_Stat tests. * * @package Resque/Tests - * @author Chris Boulton - * @copyright (c) 2010 Chris Boulton + * @author Chris Boulton * @license http://www.opensource.org/licenses/mit-license.php */ class Resque_Tests_StatTest extends Resque_Tests_TestCase diff --git a/test/Resque/Tests/TestCase.php b/test/Resque/Tests/TestCase.php index f4c00df..6c052d3 100644 --- a/test/Resque/Tests/TestCase.php +++ b/test/Resque/Tests/TestCase.php @@ -3,8 +3,7 @@ * Resque test case class. Contains setup and teardown methods. * * @package Resque/Tests - * @author Chris Boulton - * @copyright (c) 2010 Chris Boulton + * @author Chris Boulton * @license http://www.opensource.org/licenses/mit-license.php */ class Resque_Tests_TestCase extends PHPUnit_Framework_TestCase diff --git a/test/Resque/Tests/WorkerTest.php b/test/Resque/Tests/WorkerTest.php index 47b0208..f6199af 100644 --- a/test/Resque/Tests/WorkerTest.php +++ b/test/Resque/Tests/WorkerTest.php @@ -5,8 +5,7 @@ require_once dirname(__FILE__) . '/bootstrap.php'; * Resque_Worker tests. * * @package Resque/Tests - * @author Chris Boulton - * @copyright (c) 2010 Chris Boulton + * @author Chris Boulton * @license http://www.opensource.org/licenses/mit-license.php */ class Resque_Tests_WorkerTest extends Resque_Tests_TestCase diff --git a/test/Resque/Tests/bootstrap.php b/test/Resque/Tests/bootstrap.php index 0efa2a8..7671e43 100644 --- a/test/Resque/Tests/bootstrap.php +++ b/test/Resque/Tests/bootstrap.php @@ -3,8 +3,7 @@ * Resque test bootstrap file - sets up a test environment. * * @package Resque/Tests - * @author Chris Boulton - * @copyright (c) 2010 Chris Boulton + * @author Chris Boulton * @license http://www.opensource.org/licenses/mit-license.php */ define('CWD', dirname(__FILE__)); From 02141982b1914caea7b0a3e15e69ac704b574dfd Mon Sep 17 00:00:00 2001 From: Chris Boulton Date: Sat, 13 Oct 2012 17:58:42 +1100 Subject: [PATCH 04/37] remove bin/resque, which is empty --- bin/resque | 1 - 1 file changed, 1 deletion(-) delete mode 100644 bin/resque diff --git a/bin/resque b/bin/resque deleted file mode 100644 index 1a24852..0000000 --- a/bin/resque +++ /dev/null @@ -1 +0,0 @@ -#!/bin/sh From aeb0ddcf0820e7738d4d689a36a98806732bf57f Mon Sep 17 00:00:00 2001 From: Chris Boulton Date: Sat, 13 Oct 2012 17:59:01 +1100 Subject: [PATCH 05/37] update changelog to mention changes coming to php-resque --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e97469..f3b5e9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ * Add support for Composer * Fix missing and incorrect paths for Resque and Resque_Job_Status classes in demo (jjfrey) * Disable autoload for the RedisException class_exists call (scragg0x) +* General tidyup of comments and files/folders ## 1.1 (2011-03-27) ## From 8d05f92a22f21ac7a032db3c7ab168d978031967 Mon Sep 17 00:00:00 2001 From: Chris Boulton Date: Sat, 13 Oct 2012 18:10:53 +1100 Subject: [PATCH 06/37] remove old TODO file --- TODO.md | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 TODO.md diff --git a/TODO.md b/TODO.md deleted file mode 100644 index 61ea867..0000000 --- a/TODO.md +++ /dev/null @@ -1,8 +0,0 @@ -* Write tests for: - * `Resque_Failure` - * `Resque_Failure_Redis` -* Change to preforking worker model -* Clean up /bin and /demo -* Add a way to store arbitrary text in job statuses (for things like progress -indicators) -* Write plugin for Ruby resque that calls setUp and tearDown methods \ No newline at end of file From d055a7e00bd2869ec95bf94f78708e19c9926871 Mon Sep 17 00:00:00 2001 From: Chris Boulton Date: Sat, 13 Oct 2012 18:21:20 +1100 Subject: [PATCH 07/37] add note about future backwards compatibility --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3b5e9f..2992de8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## 1.2 (2012-10-13) ## +**Note:** This release is largely backwards compatible with php-resque 1.1. The next release will introduce backwards incompatible changes (moving from Redisent to Credis), and will drop compatibility with PHP 5.2. + * Allow alternate redis database to be selected when calling setBackend by supplying a second argument (patrickbajao) * Use `require_once` when including php-resque after the app has been included in the sample resque.php to prevent include conflicts (andrewjshults) * Wrap job arguments in an array to improve compatibility with ruby resque (warezthebeef) From bf91b4cc6b793c3317dbe0b4659a756c06e7937a Mon Sep 17 00:00:00 2001 From: Chris Boulton Date: Sat, 13 Oct 2012 18:23:06 +1100 Subject: [PATCH 08/37] update contributors --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 2f942ab..afc8956 100644 --- a/README.md +++ b/README.md @@ -329,3 +329,16 @@ Called after a job has been queued using the `Resque::enqueue` method. Arguments * KevBurnsJr * jmathai * dceballos +* patrickbajao +* andrewjshults +* warezthebeef +* d11wtq +* hlegius +* salimane +* humancopy +* pedroarnal +* chaitanyakuber +* maetl +* Matt Heath +* jjfrey +* scragg0x \ No newline at end of file From 0549d6c88a4aed934655b7c03b6153349d6c3ad0 Mon Sep 17 00:00:00 2001 From: Chris Boulton Date: Sat, 13 Oct 2012 18:28:16 +1100 Subject: [PATCH 09/37] update version to 1.2 --- lib/Resque.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Resque.php b/lib/Resque.php index 5362b5b..a3150cb 100644 --- a/lib/Resque.php +++ b/lib/Resque.php @@ -11,7 +11,7 @@ require_once dirname(__FILE__) . '/Resque/Exception.php'; */ class Resque { - const VERSION = '1.0'; + const VERSION = '1.2'; /** * @var Resque_Redis Instance of Resque_Redis that talks to redis. From 3314d407eba016c8c3e932040475691f95ef8a20 Mon Sep 17 00:00:00 2001 From: Chris Boulton Date: Sat, 13 Oct 2012 18:32:05 +1100 Subject: [PATCH 10/37] stop testing on php 5.2 --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1284d21..625062e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,4 @@ language: php php: - - 5.2 - 5.3 - 5.4 From 3955bc8edc410c68c57e44120b709465101e090a Mon Sep 17 00:00:00 2001 From: Allen Torres Date: Thu, 1 Nov 2012 09:28:47 -0400 Subject: [PATCH 11/37] Updated recreate method in Resque_Job class to set arguments in the same fashion as getAruments returns them. --- lib/Resque/Job.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Resque/Job.php b/lib/Resque/Job.php index 661bd3c..e673c4f 100755 --- a/lib/Resque/Job.php +++ b/lib/Resque/Job.php @@ -231,7 +231,7 @@ class Resque_Job $monitor = true; } - return self::create($this->queue, $this->payload['class'], $this->payload['args'], $monitor); + return self::create($this->queue, $this->payload['class'], $this->payload['args'][0], $monitor); } /** From f6334bb3b89a604e36440065b36e0de6ac96207a Mon Sep 17 00:00:00 2001 From: Allen Torres Date: Thu, 1 Nov 2012 09:37:06 -0400 Subject: [PATCH 12/37] Added a check to see if we have args before we attempt to access the first item in the payload args to prevent an undefined index error. --- lib/Resque/Job.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Resque/Job.php b/lib/Resque/Job.php index e673c4f..0e03f04 100755 --- a/lib/Resque/Job.php +++ b/lib/Resque/Job.php @@ -230,8 +230,9 @@ class Resque_Job if($status->isTracking()) { $monitor = true; } - - return self::create($this->queue, $this->payload['class'], $this->payload['args'][0], $monitor); + $args = count($this->payload['args'])? $this->payload['args'][0] : $this->payload['args']; + + return self::create($this->queue, $this->payload['class'], $args, $monitor); } /** From 7f1cf35a62d92327f20f7b752e219c50d5fef9a0 Mon Sep 17 00:00:00 2001 From: Tony Piper Date: Mon, 26 Nov 2012 15:23:57 +0000 Subject: [PATCH 13/37] implement prefix removel --- lib/Resque/Redis.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/Resque/Redis.php b/lib/Resque/Redis.php index 053f2f9..5e18a01 100644 --- a/lib/Resque/Redis.php +++ b/lib/Resque/Redis.php @@ -113,5 +113,20 @@ class Resque_Redis extends Redisent return false; } } + + public static function getPrefix() + { + return self::$defaultNamespace; + } + + public static function removePrefix($string) + { + $prefix=self::getPrefix(); + + if (substr($string, 0, strlen($prefix)) == $prefix) { + $string = substr($string, strlen($prefix), strlen($string) ); + } + return $string; + } } ?> \ No newline at end of file From e4f39a60931e68e83d963c44d8c42615ec70f188 Mon Sep 17 00:00:00 2001 From: Allen Torres Date: Fri, 28 Dec 2012 09:33:09 -0500 Subject: [PATCH 14/37] Updated Redisent.php to attempt three reconnects to the redis server before giving up. Also supressed fwrite errors. --- lib/Redisent/Redisent.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/Redisent/Redisent.php b/lib/Redisent/Redisent.php index 4b480f6..727f16b 100644 --- a/lib/Redisent/Redisent.php +++ b/lib/Redisent/Redisent.php @@ -43,6 +43,13 @@ class Redisent { * @access public */ public $port; + + /** + * Number of times to attempt a reconnect + * + * @var int + */ + public $max_reconnects = 3; /** * Creates a Redisent connection to the Redis server on host {@link $host} and port {@link $port}. @@ -73,10 +80,17 @@ class Redisent { $command = sprintf('*%d%s%s%s', count($args), CRLF, implode(array_map(array($this, 'formatArgument'), $args), CRLF), CRLF); /* Open a Redis connection and execute the command */ + $reconnects = 0; for ($written = 0; $written < strlen($command); $written += $fwrite) { - $fwrite = fwrite($this->__sock, substr($command, $written)); - if ($fwrite === FALSE) { - throw new Exception('Failed to write entire command to stream'); + $fwrite = @fwrite($this->__sock, substr($command, $written)); + if ($fwrite === FALSE || $fwrite === 0) { + if ($reconnects >= (int)$this->max_reconnects) { + throw new Exception('Failed to write entire command to stream'); + }else{ + fclose($this->__sock); + $this->establishConnection(); + $reconnects++; + } } } From 0afb87663f113cd09d411621beb7c7b72bc89253 Mon Sep 17 00:00:00 2001 From: Allen Torres Date: Fri, 28 Dec 2012 10:33:32 -0500 Subject: [PATCH 15/37] Reverted changes made to upstream master. --- lib/Resque/Job.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Resque/Job.php b/lib/Resque/Job.php index 0e03f04..e673c4f 100755 --- a/lib/Resque/Job.php +++ b/lib/Resque/Job.php @@ -230,9 +230,8 @@ class Resque_Job if($status->isTracking()) { $monitor = true; } - $args = count($this->payload['args'])? $this->payload['args'][0] : $this->payload['args']; - - return self::create($this->queue, $this->payload['class'], $args, $monitor); + + return self::create($this->queue, $this->payload['class'], $this->payload['args'][0], $monitor); } /** From a5b70a5cbd087f2b2c697a698a8ff64074535203 Mon Sep 17 00:00:00 2001 From: Allen Torres Date: Fri, 28 Dec 2012 10:39:34 -0500 Subject: [PATCH 16/37] Added a sleep call for a second before establishing another connection. --- lib/Redisent/Redisent.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Redisent/Redisent.php b/lib/Redisent/Redisent.php index 727f16b..92ccd02 100644 --- a/lib/Redisent/Redisent.php +++ b/lib/Redisent/Redisent.php @@ -88,6 +88,7 @@ class Redisent { throw new Exception('Failed to write entire command to stream'); }else{ fclose($this->__sock); + sleep(1); $this->establishConnection(); $reconnects++; } From fdc9f881e8b40cdb4a3fdb540ac1afdce0a0ca2f Mon Sep 17 00:00:00 2001 From: Allen Torres Date: Fri, 28 Dec 2012 10:42:16 -0500 Subject: [PATCH 17/37] Reverted changes made from upstream master. --- lib/Resque/Job.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Resque/Job.php b/lib/Resque/Job.php index e673c4f..661bd3c 100755 --- a/lib/Resque/Job.php +++ b/lib/Resque/Job.php @@ -231,7 +231,7 @@ class Resque_Job $monitor = true; } - return self::create($this->queue, $this->payload['class'], $this->payload['args'][0], $monitor); + return self::create($this->queue, $this->payload['class'], $this->payload['args'], $monitor); } /** From 5127aefa904773de899dfe1394bbcc3bbd0196fd Mon Sep 17 00:00:00 2001 From: Daniel Hunsaker Date: Fri, 11 Jan 2013 13:40:39 -0700 Subject: [PATCH 18/37] Update lib/Resque/Redis.php Add SETEX to the list of commands which supply a key as the first argument. --- lib/Resque/Redis.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Resque/Redis.php b/lib/Resque/Redis.php index 5e18a01..dcfc47d 100644 --- a/lib/Resque/Redis.php +++ b/lib/Resque/Redis.php @@ -33,6 +33,7 @@ class Resque_Redis extends Redisent 'ttl', 'move', 'set', + 'setex', 'get', 'getset', 'setnx', @@ -129,4 +130,4 @@ class Resque_Redis extends Redisent return $string; } } -?> \ No newline at end of file +?> From e72c31a4501e6b207ec3c38e569b1dec6d3a8a83 Mon Sep 17 00:00:00 2001 From: Chris Boulton Date: Sat, 12 Jan 2013 21:45:06 +1100 Subject: [PATCH 19/37] ignore vendor/ --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a725465 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +vendor/ \ No newline at end of file From 8a7f11f906d4e692666396bb33ac250e07a7e807 Mon Sep 17 00:00:00 2001 From: Chris Boulton Date: Sat, 12 Jan 2013 21:47:07 +1100 Subject: [PATCH 20/37] add phpunit as a development requirement --- composer.json | 3 + composer.lock | 408 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 411 insertions(+) create mode 100644 composer.lock diff --git a/composer.json b/composer.json index 594f13f..79d3840 100644 --- a/composer.json +++ b/composer.json @@ -14,6 +14,9 @@ "require": { "php": ">=5.3.0" }, + "require-dev": { + "phpunit/phpunit": "3.7.*" + }, "autoload": { "psr-0": { "Resque": "lib" diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..64c1bce --- /dev/null +++ b/composer.lock @@ -0,0 +1,408 @@ +{ + "hash": "3df3cf88489d7751f032e8205ebcda7c", + "packages": [ + + ], + "packages-dev": [ + { + "name": "phpunit/php-code-coverage", + "version": "1.2.7", + "source": { + "type": "git", + "url": "git://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "1.2.7" + }, + "dist": { + "type": "zip", + "url": "https://github.com/sebastianbergmann/php-code-coverage/archive/1.2.7.zip", + "reference": "1.2.7", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "phpunit/php-file-iterator": ">=1.3.0@stable", + "phpunit/php-token-stream": ">=1.1.3@stable", + "phpunit/php-text-template": ">=1.1.1@stable" + }, + "suggest": { + "ext-dom": "*", + "ext-xdebug": ">=2.0.5" + }, + "time": "2012-12-02 14:54:55", + "type": "library", + "autoload": { + "classmap": [ + "PHP/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "testing", + "coverage", + "xunit" + ] + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.3.3", + "source": { + "type": "git", + "url": "git://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "1.3.3" + }, + "dist": { + "type": "zip", + "url": "https://github.com/sebastianbergmann/php-file-iterator/zipball/1.3.3", + "reference": "1.3.3", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "time": "2012-10-11 04:44:38", + "type": "library", + "autoload": { + "classmap": [ + "File/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "http://www.phpunit.de/", + "keywords": [ + "filesystem", + "iterator" + ] + }, + { + "name": "phpunit/php-text-template", + "version": "1.1.4", + "source": { + "type": "git", + "url": "git://github.com/sebastianbergmann/php-text-template.git", + "reference": "1.1.4" + }, + "dist": { + "type": "zip", + "url": "https://github.com/sebastianbergmann/php-text-template/zipball/1.1.4", + "reference": "1.1.4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "time": "2012-10-31 11:15:28", + "type": "library", + "autoload": { + "classmap": [ + "Text/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ] + }, + { + "name": "phpunit/php-timer", + "version": "1.0.4", + "source": { + "type": "git", + "url": "git://github.com/sebastianbergmann/php-timer.git", + "reference": "1.0.4" + }, + "dist": { + "type": "zip", + "url": "https://github.com/sebastianbergmann/php-timer/zipball/1.0.4", + "reference": "1.0.4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "time": "2012-10-11 04:45:58", + "type": "library", + "autoload": { + "classmap": [ + "PHP/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "http://www.phpunit.de/", + "keywords": [ + "timer" + ] + }, + { + "name": "phpunit/php-token-stream", + "version": "1.1.5", + "source": { + "type": "git", + "url": "git://github.com/sebastianbergmann/php-token-stream.git", + "reference": "1.1.5" + }, + "dist": { + "type": "zip", + "url": "https://github.com/sebastianbergmann/php-token-stream/zipball/1.1.5", + "reference": "1.1.5", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.3.3" + }, + "time": "2012-10-11 04:47:14", + "type": "library", + "autoload": { + "classmap": [ + "PHP/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "http://www.phpunit.de/", + "keywords": [ + "tokenizer" + ] + }, + { + "name": "phpunit/phpunit", + "version": "3.7.12", + "source": { + "type": "git", + "url": "git://github.com/sebastianbergmann/phpunit.git", + "reference": "3.7.12" + }, + "dist": { + "type": "zip", + "url": "https://github.com/sebastianbergmann/phpunit/archive/3.7.12.zip", + "reference": "3.7.12", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "phpunit/php-file-iterator": ">=1.3.1", + "phpunit/php-text-template": ">=1.1.1", + "phpunit/php-code-coverage": ">=1.2.1", + "phpunit/php-timer": ">=1.0.2", + "phpunit/phpunit-mock-objects": ">=1.2.0,<1.3.0", + "symfony/yaml": ">=2.1.0,<2.2.0", + "ext-dom": "*", + "ext-pcre": "*", + "ext-reflection": "*", + "ext-spl": "*" + }, + "suggest": { + "phpunit/php-invoker": ">=1.1.0", + "ext-json": "*", + "ext-simplexml": "*", + "ext-tokenizer": "*" + }, + "time": "2013-01-09 22:41:02", + "bin": [ + "composer/bin/phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.7.x-dev" + } + }, + "autoload": { + "classmap": [ + "PHPUnit/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "", + "../../symfony/yaml/" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "http://www.phpunit.de/", + "keywords": [ + "testing", + "phpunit", + "xunit" + ] + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "1.2.2", + "source": { + "type": "git", + "url": "git://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "1.2.2" + }, + "dist": { + "type": "zip", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects/archive/1.2.2.zip", + "reference": "1.2.2", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "phpunit/php-text-template": ">=1.1.1@stable" + }, + "suggest": { + "ext-soap": "*" + }, + "time": "2012-11-05 10:39:13", + "type": "library", + "autoload": { + "classmap": [ + "PHPUnit/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ] + }, + { + "name": "symfony/yaml", + "version": "v2.1.6", + "target-dir": "Symfony/Component/Yaml", + "source": { + "type": "git", + "url": "https://github.com/symfony/Yaml", + "reference": "v2.1.6" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/Yaml/archive/v2.1.6.zip", + "reference": "v2.1.6", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "time": "2012-12-06 10:00:55", + "type": "library", + "autoload": { + "psr-0": { + "Symfony\\Component\\Yaml": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony Yaml Component", + "homepage": "http://symfony.com" + } + ], + "aliases": [ + + ], + "minimum-stability": "stable", + "stability-flags": [ + + ] +} From 8d6da214732179b223252f3bcb21ece9558f2af0 Mon Sep 17 00:00:00 2001 From: Chris Boulton Date: Sat, 12 Jan 2013 22:01:13 +1100 Subject: [PATCH 21/37] restructure tests, use composer to autoload test requirements --- .travis.yml | 2 ++ phpunit.xml | 3 ++- test/Resque/Tests/EventTest.php | 2 -- test/Resque/Tests/JobStatusTest.php | 2 -- test/Resque/Tests/JobTest.php | 1 - test/Resque/Tests/StatTest.php | 2 -- test/Resque/Tests/WorkerTest.php | 2 -- test/{Resque/Tests => }/bootstrap.php | 19 +++++-------------- 8 files changed, 9 insertions(+), 24 deletions(-) rename test/{Resque/Tests => }/bootstrap.php (86%) diff --git a/.travis.yml b/.travis.yml index 625062e..b1b8e8c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,3 +2,5 @@ language: php php: - 5.3 - 5.4 +before_script: + - composer install --dev \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml index efbc7f2..61d2d7b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,7 +1,8 @@ * @license http://www.opensource.org/licenses/mit-license.php */ -define('CWD', dirname(__FILE__)); -define('RESQUE_LIB', CWD . '/../../../lib/'); -define('TEST_MISC', realpath(CWD . '/../../misc/')); +$loader = require __DIR__ . '/../vendor/autoload.php'; +$loader->add('Resque_Tests', __DIR__); + +define('TEST_MISC', realpath(__DIR__ . '/misc/')); define('REDIS_CONF', TEST_MISC . '/redis.conf'); -// Change to the directory this file lives in. This is important, due to -// how we'll be running redis. - -require_once CWD . '/TestCase.php'; - -// Include Resque -require_once RESQUE_LIB . 'Resque.php'; -require_once RESQUE_LIB . 'Resque/Worker.php'; -require_once RESQUE_LIB . 'Resque/Redis.php'; - // Attempt to start our own redis instance for tesitng. exec('which redis-server', $output, $returnVar); if($returnVar != 0) { @@ -61,7 +52,7 @@ function killRedis($pid) if (file_exists($pidFile)) { $pid = trim(file_get_contents($pidFile)); posix_kill((int) $pid, 9); - + if(is_file($pidFile)) { unlink($pidFile); } From 2f5b48930f7fcc51931d608b2d37897a350a7eea Mon Sep 17 00:00:00 2001 From: Chris Boulton Date: Sat, 12 Jan 2013 22:40:26 +1100 Subject: [PATCH 22/37] make better use of composer across php-resque * recommend php-resque be installed via Composer * provide quick getting started steps * move ./resque.php to bin/resque, make it available as a Composer bin * have classes autoloaded via Composer (or some other means if not using Composer) --- README.md | 57 ++++++++++++++++++++++++++++++---------- resque.php => bin/resque | 30 ++++++++++++++++++--- composer.json | 3 +++ composer.lock | 2 +- demo/check_status.php | 4 +-- demo/init.php | 25 ++++++++++++++++++ demo/queue.php | 2 +- demo/resque.php | 2 +- extras/resque.monit | 2 +- lib/Resque.php | 7 ----- lib/Resque/Failure.php | 2 -- lib/Resque/Job.php | 5 ---- lib/Resque/Worker.php | 5 ---- 13 files changed, 103 insertions(+), 43 deletions(-) rename resque.php => bin/resque (74%) create mode 100644 demo/init.php diff --git a/README.md b/README.md index afc8956..231aeba 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,32 @@ pre and post jobs * PHP 5.2+ * Redis 2.2+ +* Optional but Recommended: Composer + +## Getting Started ## + +The easiest way to work with php-resque is when it's installed as a +Composer package inside your project. Composer isn't strictly +required, but makes life a lot easier. + +If you're not familiar with Composer, please see . + +1. Add php-resque to your application's composer.json. + + { + ... + "require": { + "php": ">=5.3.0" + }, + ... + } + +2. Run `composer install`. + +3. If you haven't already, add the Composer autoload to your project's + initialization file. (example) + + require 'vendor/autoload.php'; ## Jobs ## @@ -46,8 +72,6 @@ pre and post jobs Jobs are queued as follows: - require_once 'lib/Resque.php'; - // Required if redis is located elsewhere Resque::setBackend('localhost:6379'); @@ -87,12 +111,12 @@ The `tearDown` method if defined, will be called after the job finishes. { // ... Set up environment for this job } - + public function perform() { // .. Run job } - + public function tearDown() { // ... Remove environment for this job @@ -136,8 +160,9 @@ class. Workers work in the exact same way as the Ruby workers. For complete documentation on workers, see the original documentation. -A basic "up-and-running" resque.php file is included that sets up a -running worker environment is included in the root directory. +A basic "up-and-running" `bin/resque` file is included that sets up a +running worker environment is included. (`vendor/bin/resque` when installed +via Composer) The exception to the similarities with the Ruby version of resque is how a worker is initially setup. To work under all environments, @@ -146,13 +171,17 @@ not having a single environment such as with Ruby, the PHP port makes To start a worker, it's very similar to the Ruby version: - $ QUEUE=file_serve php resque.php + $ QUEUE=file_serve php bin/resque It's your responsibility to tell the worker which file to include to get your application underway. You do so by setting the `APP_INCLUDE` environment variable: - $ QUEUE=file_serve APP_INCLUDE=../application/init.php php resque.php + $ QUEUE=file_serve APP_INCLUDE=../application/init.php php bin/resque + +*Pro tip: Using Composer? More than likely, you don't need to worry about +`APP_INCLUDE`, because hopefully Composer is responsible for autoloading +your application too!* Getting your application underway also includes telling the worker your job classes, by means of either an autoloader or including them. @@ -163,8 +192,8 @@ The port supports the same environment variables for logging to STDOUT. Setting `VERBOSE` will print basic debugging information and `VVERBOSE` will print detailed information. - $ VERBOSE QUEUE=file_serve php resque.php - $ VVERBOSE QUEUE=file_serve php resque.php + $ VERBOSE QUEUE=file_serve bin/resque + $ VVERBOSE QUEUE=file_serve bin/resque ### Priorities and Queue Lists ### @@ -175,7 +204,7 @@ checked in. As per the original example: - $ QUEUE=file_serve,warm_cache php resque.php + $ QUEUE=file_serve,warm_cache bin/resque The `file_serve` queue will always be checked for new jobs on each iteration before the `warm_cache` queue is checked. @@ -185,14 +214,14 @@ iteration before the `warm_cache` queue is checked. All queues are supported in the same manner and processed in alphabetical order: - $ QUEUE=* php resque.php + $ QUEUE=* bin/resque ### Running Multiple Workers ### Multiple workers ca be launched and automatically worked by supplying the `COUNT` environment variable: - $ COUNT=5 php resque.php + $ COUNT=5 bin/resque ### Forking ### @@ -257,7 +286,7 @@ It is up to your application to register event listeners. When enqueuing events in your application, it should be as easy as making sure php-resque is loaded and calling `Resque_Event::listen`. -When running workers, if you run workers via the default `resque.php` script, +When running workers, if you run workers via the default `bin/resque` script, your `APP_INCLUDE` script should initialize and register any listeners required for operation. If you have rolled your own worker manager, then it is again your responsibility to register listeners. diff --git a/resque.php b/bin/resque similarity index 74% rename from resque.php rename to bin/resque index 02ecc1a..687f6c4 100644 --- a/resque.php +++ b/bin/resque @@ -1,12 +1,34 @@ +#!/usr/bin/env php logLevel = $logLevel; - + $PIDFILE = getenv('PIDFILE'); if ($PIDFILE) { file_put_contents($PIDFILE, getmypid()) or diff --git a/composer.json b/composer.json index 79d3840..a3880ae 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,9 @@ "require-dev": { "phpunit/phpunit": "3.7.*" }, + "bin": [ + "bin/resque" + ], "autoload": { "psr-0": { "Resque": "lib" diff --git a/composer.lock b/composer.lock index 64c1bce..91301f7 100644 --- a/composer.lock +++ b/composer.lock @@ -1,5 +1,5 @@ { - "hash": "3df3cf88489d7751f032e8205ebcda7c", + "hash": "b05c2c31be6cac834e33b1a7fe61d063", "packages": [ ], diff --git a/demo/check_status.php b/demo/check_status.php index c195911..061a83a 100644 --- a/demo/check_status.php +++ b/demo/check_status.php @@ -3,8 +3,8 @@ if(empty($argv[1])) { die('Specify the ID of a job to monitor the status of.'); } -require '../lib/Resque/Job/Status.php'; -require '../lib/Resque.php'; +require __DIR__ . '/init.php'; + date_default_timezone_set('GMT'); Resque::setBackend('127.0.0.1:6379'); diff --git a/demo/init.php b/demo/init.php new file mode 100644 index 0000000..9078bcd --- /dev/null +++ b/demo/init.php @@ -0,0 +1,25 @@ + \ No newline at end of file diff --git a/extras/resque.monit b/extras/resque.monit index 654815d..b611f8f 100644 --- a/extras/resque.monit +++ b/extras/resque.monit @@ -9,7 +9,7 @@ check process resque_worker_[QUEUE] with pidfile /var/run/resque/worker_[QUEUE].pid - start program = "/bin/sh -c 'APP_INCLUDE=[APP_INCLUDE] QUEUE=[QUEUE] VERBOSE=1 PIDFILE=/var/run/resque/worker_[QUEUE].pid nohup php -f [PATH/TO/RESQUE]/resque.php > /var/log/resque/worker_[QUEUE].log &'" as uid [UID] and gid [GID] + start program = "/bin/sh -c 'APP_INCLUDE=[APP_INCLUDE] QUEUE=[QUEUE] VERBOSE=1 PIDFILE=/var/run/resque/worker_[QUEUE].pid nohup php -f [PATH/TO/RESQUE]/bin/resque > /var/log/resque/worker_[QUEUE].log &'" as uid [UID] and gid [GID] stop program = "/bin/sh -c 'kill -s QUIT `cat /var/run/resque/worker_[QUEUE].pid` && rm -f /var/run/resque/worker_[QUEUE].pid; exit 0;'" if totalmem is greater than 300 MB for 10 cycles then restart # eating up memory? group resque_workers \ No newline at end of file diff --git a/lib/Resque.php b/lib/Resque.php index a3150cb..c3254a3 100644 --- a/lib/Resque.php +++ b/lib/Resque.php @@ -1,7 +1,4 @@ updateStatus(Resque_Job_Status::STATUS_FAILED); - require_once dirname(__FILE__) . '/Failure.php'; Resque_Failure::create( $this->payload, $exception, diff --git a/lib/Resque/Worker.php b/lib/Resque/Worker.php index 5aa1ccd..d103810 100644 --- a/lib/Resque/Worker.php +++ b/lib/Resque/Worker.php @@ -1,9 +1,4 @@ Date: Sat, 12 Jan 2013 22:54:42 +1100 Subject: [PATCH 23/37] update changelog --- CHANGELOG.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2992de8..0e27544 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,24 @@ +## 1.3 (2013-??-??) - Current Master ## + +**Note:** This release introduces backwards incompatible changes with all previous versions of php-resque. Please see below for details. + +### Composer Support + +Composer support has been improved and is now the recommended method for including php-resque in your project. Details on Composer support can be found in the Getting Started section of the readme. + +### Other Improvements/Changes + +* **COMPATIBILITY BREAKING**: The bundled worker manager `resque.php` has been moved to `bin/resque`, and is available as `vendor/bin/resque` when php-resque is installed as a Composer package. + +* Restructure tests and test bootstrapping. Autoload tests via Composer (install test dependencies with `composer install --dev`) + +* Add `SETEX` to list of commands which supply a key as the first argument in Redisent (danhunsaker) + +* Fix an issue where a lost connection to Redis could cause an infinite loop (atorres757) + +* Add a helper method to `Resque_Redis` to remove the namespace applied to Redis keys (tonypiper) + + ## 1.2 (2012-10-13) ## **Note:** This release is largely backwards compatible with php-resque 1.1. The next release will introduce backwards incompatible changes (moving from Redisent to Credis), and will drop compatibility with PHP 5.2. @@ -22,7 +43,7 @@ * Add support for Composer * Fix missing and incorrect paths for Resque and Resque_Job_Status classes in demo (jjfrey) * Disable autoload for the RedisException class_exists call (scragg0x) -* General tidyup of comments and files/folders +* General tidy up of comments and files/folders ## 1.1 (2011-03-27) ## From a77699549bb51e5b00f7fd8f17860faec727657f Mon Sep 17 00:00:00 2001 From: Chris Boulton Date: Sat, 12 Jan 2013 23:06:55 +1100 Subject: [PATCH 24/37] bump php requirement up to 5.3 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 231aeba..2b94eac 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ pre and post jobs ## Requirements ## -* PHP 5.2+ +* PHP 5.3+ * Redis 2.2+ * Optional but Recommended: Composer From a6eb8e1c45875f8e8a809fd2ed38b6f55c90c626 Mon Sep 17 00:00:00 2001 From: Chris Boulton Date: Sat, 12 Jan 2013 23:07:15 +1100 Subject: [PATCH 25/37] use __DIR__ --- lib/Redisent/RedisentCluster.php | 2 +- lib/Resque/Redis.php | 2 +- lib/Resque/RedisCluster.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Redisent/RedisentCluster.php b/lib/Redisent/RedisentCluster.php index ea93611..215726e 100644 --- a/lib/Redisent/RedisentCluster.php +++ b/lib/Redisent/RedisentCluster.php @@ -7,7 +7,7 @@ * @package Redisent */ -require_once dirname(__FILE__) . '/Redisent.php'; +require_once __DIR__ . '/Redisent.php'; /** * A generalized Redisent interface for a cluster of Redis servers diff --git a/lib/Resque/Redis.php b/lib/Resque/Redis.php index dcfc47d..1cff624 100644 --- a/lib/Resque/Redis.php +++ b/lib/Resque/Redis.php @@ -2,7 +2,7 @@ // Third- party apps may have already loaded Resident from elsewhere // so lets be careful. if(!class_exists('Redisent', false)) { - require_once dirname(__FILE__) . '/../Redisent/Redisent.php'; + require_once __DIR__ . '/../Redisent/Redisent.php'; } /** diff --git a/lib/Resque/RedisCluster.php b/lib/Resque/RedisCluster.php index 100bdb7..21caeb7 100644 --- a/lib/Resque/RedisCluster.php +++ b/lib/Resque/RedisCluster.php @@ -2,7 +2,7 @@ // Third- party apps may have already loaded Resident from elsewhere // so lets be careful. if(!class_exists('RedisentCluster', false)) { - require_once dirname(__FILE__) . '/../Redisent/RedisentCluster.php'; + require_once __DIR__ . '/../Redisent/RedisentCluster.php'; } /** From 2ba15eb555b5cda349b0211b11bb70883f27af25 Mon Sep 17 00:00:00 2001 From: Chris Boulton Date: Sat, 12 Jan 2013 23:37:38 +1100 Subject: [PATCH 26/37] replace Redisent with Credis (also adds native phpredis support) --- CHANGELOG.md | 8 + composer.json | 9 +- composer.lock | 399 ++----------------------------- lib/Redisent/LICENSE | 22 -- lib/Redisent/README.markdown | 67 ------ lib/Redisent/Redisent.php | 165 ------------- lib/Redisent/RedisentCluster.php | 138 ----------- lib/Resque.php | 16 +- lib/Resque/Redis.php | 57 +++-- lib/Resque/RedisCluster.php | 117 --------- test/Resque/Tests/TestCase.php | 2 +- 11 files changed, 81 insertions(+), 919 deletions(-) delete mode 100644 lib/Redisent/LICENSE delete mode 100644 lib/Redisent/README.markdown delete mode 100644 lib/Redisent/Redisent.php delete mode 100644 lib/Redisent/RedisentCluster.php delete mode 100644 lib/Resque/RedisCluster.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e27544..f6f1196 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ **Note:** This release introduces backwards incompatible changes with all previous versions of php-resque. Please see below for details. +### Redisent (Redis Library) Replaced with Credis + +Redisent has always been the Redis backend for php-resque because of its lightweight nature. Unfortunately, Redisent is largely unmaintained. + +[Credis](http://example.com/) is a fork of Redisent, which among other improvements will automatically use the [phpredis](https://github.com/nicolasff/phpredis) native PHP extension if it is available. (you want this for speed, trust me) + +php-resque now utilizes Credis for all Redis based operations. Credis automatically required and installed as a Composer dependency. + ### Composer Support Composer support has been improved and is now the recommended method for including php-resque in your project. Details on Composer support can be found in the Getting Started section of the readme. diff --git a/composer.json b/composer.json index a3880ae..9b67eae 100644 --- a/composer.json +++ b/composer.json @@ -11,8 +11,15 @@ "email": "chris@bigcommerce.com" } ], + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/chrisboulton/credis" + } + ], "require": { - "php": ">=5.3.0" + "php": ">=5.3.0", + "colinmollenhour/credis": "dev-master" }, "require-dev": { "phpunit/phpunit": "3.7.*" diff --git a/composer.lock b/composer.lock index 91301f7..472226f 100644 --- a/composer.lock +++ b/composer.lock @@ -1,408 +1,53 @@ { - "hash": "b05c2c31be6cac834e33b1a7fe61d063", + "hash": "af626b3a277bd0ab503c2c107327a88e", "packages": [ - - ], - "packages-dev": [ { - "name": "phpunit/php-code-coverage", - "version": "1.2.7", + "name": "colinmollenhour/credis", + "version": "dev-master", "source": { "type": "git", - "url": "git://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "1.2.7" + "url": "https://github.com/chrisboulton/credis", + "reference": "62c73dd16e08069e3fd8f224cb4a5ddd73db8095" }, "dist": { "type": "zip", - "url": "https://github.com/sebastianbergmann/php-code-coverage/archive/1.2.7.zip", - "reference": "1.2.7", + "url": "https://api.github.com/repos/chrisboulton/credis/zipball/62c73dd16e08069e3fd8f224cb4a5ddd73db8095", + "reference": "62c73dd16e08069e3fd8f224cb4a5ddd73db8095", "shasum": "" }, "require": { - "php": ">=5.3.3", - "phpunit/php-file-iterator": ">=1.3.0@stable", - "phpunit/php-token-stream": ">=1.1.3@stable", - "phpunit/php-text-template": ">=1.1.1@stable" + "php": ">=5.3.0" }, - "suggest": { - "ext-dom": "*", - "ext-xdebug": ">=2.0.5" - }, - "time": "2012-12-02 14:54:55", + "time": "2013-01-12 10:15:31", "type": "library", "autoload": { "classmap": [ - "PHP/" + "Client.php", + "Cluster.php" ] }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", - "homepage": "https://github.com/sebastianbergmann/php-code-coverage", - "keywords": [ - "testing", - "coverage", - "xunit" - ] - }, - { - "name": "phpunit/php-file-iterator", - "version": "1.3.3", - "source": { - "type": "git", - "url": "git://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "1.3.3" - }, - "dist": { - "type": "zip", - "url": "https://github.com/sebastianbergmann/php-file-iterator/zipball/1.3.3", - "reference": "1.3.3", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "time": "2012-10-11 04:44:38", - "type": "library", - "autoload": { - "classmap": [ - "File/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "FilterIterator implementation that filters files based on a list of suffixes.", - "homepage": "http://www.phpunit.de/", - "keywords": [ - "filesystem", - "iterator" - ] - }, - { - "name": "phpunit/php-text-template", - "version": "1.1.4", - "source": { - "type": "git", - "url": "git://github.com/sebastianbergmann/php-text-template.git", - "reference": "1.1.4" - }, - "dist": { - "type": "zip", - "url": "https://github.com/sebastianbergmann/php-text-template/zipball/1.1.4", - "reference": "1.1.4", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "time": "2012-10-31 11:15:28", - "type": "library", - "autoload": { - "classmap": [ - "Text/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Simple template engine.", - "homepage": "https://github.com/sebastianbergmann/php-text-template/", - "keywords": [ - "template" - ] - }, - { - "name": "phpunit/php-timer", - "version": "1.0.4", - "source": { - "type": "git", - "url": "git://github.com/sebastianbergmann/php-timer.git", - "reference": "1.0.4" - }, - "dist": { - "type": "zip", - "url": "https://github.com/sebastianbergmann/php-timer/zipball/1.0.4", - "reference": "1.0.4", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "time": "2012-10-11 04:45:58", - "type": "library", - "autoload": { - "classmap": [ - "PHP/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Utility class for timing", - "homepage": "http://www.phpunit.de/", - "keywords": [ - "timer" - ] - }, - { - "name": "phpunit/php-token-stream", - "version": "1.1.5", - "source": { - "type": "git", - "url": "git://github.com/sebastianbergmann/php-token-stream.git", - "reference": "1.1.5" - }, - "dist": { - "type": "zip", - "url": "https://github.com/sebastianbergmann/php-token-stream/zipball/1.1.5", - "reference": "1.1.5", - "shasum": "" - }, - "require": { - "ext-tokenizer": "*", - "php": ">=5.3.3" - }, - "time": "2012-10-11 04:47:14", - "type": "library", - "autoload": { - "classmap": [ - "PHP/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Wrapper around PHP's tokenizer extension.", - "homepage": "http://www.phpunit.de/", - "keywords": [ - "tokenizer" - ] - }, - { - "name": "phpunit/phpunit", - "version": "3.7.12", - "source": { - "type": "git", - "url": "git://github.com/sebastianbergmann/phpunit.git", - "reference": "3.7.12" - }, - "dist": { - "type": "zip", - "url": "https://github.com/sebastianbergmann/phpunit/archive/3.7.12.zip", - "reference": "3.7.12", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "phpunit/php-file-iterator": ">=1.3.1", - "phpunit/php-text-template": ">=1.1.1", - "phpunit/php-code-coverage": ">=1.2.1", - "phpunit/php-timer": ">=1.0.2", - "phpunit/phpunit-mock-objects": ">=1.2.0,<1.3.0", - "symfony/yaml": ">=2.1.0,<2.2.0", - "ext-dom": "*", - "ext-pcre": "*", - "ext-reflection": "*", - "ext-spl": "*" - }, - "suggest": { - "phpunit/php-invoker": ">=1.1.0", - "ext-json": "*", - "ext-simplexml": "*", - "ext-tokenizer": "*" - }, - "time": "2013-01-09 22:41:02", - "bin": [ - "composer/bin/phpunit" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.7.x-dev" - } - }, - "autoload": { - "classmap": [ - "PHPUnit/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "", - "../../symfony/yaml/" - ], - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "The PHP Unit Testing framework.", - "homepage": "http://www.phpunit.de/", - "keywords": [ - "testing", - "phpunit", - "xunit" - ] - }, - { - "name": "phpunit/phpunit-mock-objects", - "version": "1.2.2", - "source": { - "type": "git", - "url": "git://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "1.2.2" - }, - "dist": { - "type": "zip", - "url": "https://github.com/sebastianbergmann/phpunit-mock-objects/archive/1.2.2.zip", - "reference": "1.2.2", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "phpunit/php-text-template": ">=1.1.1@stable" - }, - "suggest": { - "ext-soap": "*" - }, - "time": "2012-11-05 10:39:13", - "type": "library", - "autoload": { - "classmap": [ - "PHPUnit/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Mock Object library for PHPUnit", - "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", - "keywords": [ - "mock", - "xunit" - ] - }, - { - "name": "symfony/yaml", - "version": "v2.1.6", - "target-dir": "Symfony/Component/Yaml", - "source": { - "type": "git", - "url": "https://github.com/symfony/Yaml", - "reference": "v2.1.6" - }, - "dist": { - "type": "zip", - "url": "https://github.com/symfony/Yaml/archive/v2.1.6.zip", - "reference": "v2.1.6", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "time": "2012-12-06 10:00:55", - "type": "library", - "autoload": { - "psr-0": { - "Symfony\\Component\\Yaml": "" - } - }, - "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" + "name": "Colin Mollenhour", + "email": "colin@mollenhour.com" } ], - "description": "Symfony Yaml Component", - "homepage": "http://symfony.com" + "description": "Credis is a lightweight interface to the Redis key-value store which wraps the phpredis library when available for better performance.", + "homepage": "https://github.com/colinmollenhour/credis", + "support": { + "source": "https://github.com/chrisboulton/credis/tree/master" + } } ], + "packages-dev": null, "aliases": [ ], "minimum-stability": "stable", - "stability-flags": [ - - ] + "stability-flags": { + "colinmollenhour/credis": 20 + } } diff --git a/lib/Redisent/LICENSE b/lib/Redisent/LICENSE deleted file mode 100644 index 385910f..0000000 --- a/lib/Redisent/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2009 Justin Poliey - -Permission is hereby granted, free of charge, to any person -obtaining a copy of this software and associated documentation -files (the "Software"), to deal in the Software without -restriction, including without limitation the rights to use, -copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/lib/Redisent/README.markdown b/lib/Redisent/README.markdown deleted file mode 100644 index 3edb843..0000000 --- a/lib/Redisent/README.markdown +++ /dev/null @@ -1,67 +0,0 @@ -# Redisent - -Redisent is a simple, no-nonsense interface to the [Redis](http://code.google.com/p/redis/) key-value store for modest developers. -Due to the way it is implemented, it is flexible and tolerant of changes to the Redis protocol. - -## Getting to work - -If you're at all familiar with the Redis protocol and PHP objects, you've already mastered Redisent. -All Redisent does is map the Redis protocol to a PHP object, abstract away the nitty-gritty, and make the return values PHP compatible. - - require 'redisent.php'; - $redis = new Redisent('localhost'); - $redis->set('awesome', 'absolutely'); - echo sprintf('Is Redisent awesome? %s.\n', $redis->get('awesome')); - -You use the exact same command names, and the exact same argument order. **How wonderful.** How about a more complex example? - - require 'redisent.php'; - $redis = new Redisent('localhost'); - $redis->rpush('particles', 'proton'); - $redis->rpush('particles', 'electron'); - $redis->rpush('particles', 'neutron'); - $particles = $redis->lrange('particles', 0, -1); - $particle_count = $redis->llen('particles'); - echo "

The {$particle_count} particles that make up atoms are:

"; - echo "
    "; - foreach ($particles as $particle) { - echo "
  • {$particle}
  • "; - } - echo "
"; - -Be aware that Redis error responses will be wrapped in a RedisException class and thrown, so do be sure to use proper coding techniques. - -## Clustering your servers - -Redisent also includes a way for developers to fully utilize the scalability of Redis with multiple servers and [consistent hashing](http://en.wikipedia.org/wiki/Consistent_hashing). -Using the RedisentCluster class, you can use Redisent the same way, except that keys will be hashed across multiple servers. -Here is how to set up a cluster: - - include 'redisent_cluster.php'; - - $cluster = new RedisentCluster(array( - array('host' => '127.0.0.1', 'port' => 6379), - array('host' => '127.0.0.1', 'port' => 6380) - )); - -You can then use Redisent the way you normally would, i.e., `$cluster->set('key', 'value')` or `$cluster->lrange('particles', 0, -1)`. -But what about when you need to use commands that are server specific and do not operate on keys? You can use routing, with the `RedisentCluster::to` method. -To use routing, you need to assign a server an alias in the constructor of the Redis cluster. Aliases are not required on all servers, just the ones you want to be able to access directly. - - include 'redisent_cluster.php'; - - $cluster = new RedisentCluster(array( - 'alpha' => array('host' => '127.0.0.1', 'port' => 6379), - array('host' => '127.0.0.1', 'port' => 6380) - )); - -Now there is an alias of the server running on 127.0.0.1:6379 called **alpha**, and can be interacted with like this: - - // get server info - $cluster->to('alpha')->info(); - -Now you have complete programatic control over your Redis servers. - -## About - -© 2009 [Justin Poliey](http://justinpoliey.com) \ No newline at end of file diff --git a/lib/Redisent/Redisent.php b/lib/Redisent/Redisent.php deleted file mode 100644 index 92ccd02..0000000 --- a/lib/Redisent/Redisent.php +++ /dev/null @@ -1,165 +0,0 @@ - - * @copyright 2009 Justin Poliey - * @license http://www.opensource.org/licenses/mit-license.php The MIT License - * @package Redisent - */ - -define('CRLF', sprintf('%s%s', chr(13), chr(10))); - -/** - * Wraps native Redis errors in friendlier PHP exceptions - * Only declared if class doesn't already exist to ensure compatibility with php-redis - */ -if (! class_exists('RedisException', false)) { - class RedisException extends Exception { - } -} - -/** - * Redisent, a Redis interface for the modest among us - */ -class Redisent { - - /** - * Socket connection to the Redis server - * @var resource - * @access private - */ - private $__sock; - - /** - * Host of the Redis server - * @var string - * @access public - */ - public $host; - - /** - * Port on which the Redis server is running - * @var integer - * @access public - */ - public $port; - - /** - * Number of times to attempt a reconnect - * - * @var int - */ - public $max_reconnects = 3; - - /** - * Creates a Redisent connection to the Redis server on host {@link $host} and port {@link $port}. - * @param string $host The hostname of the Redis server - * @param integer $port The port number of the Redis server - */ - function __construct($host, $port = 6379) { - $this->host = $host; - $this->port = $port; - $this->establishConnection(); - } - - function establishConnection() { - $this->__sock = fsockopen($this->host, $this->port, $errno, $errstr); - if (!$this->__sock) { - throw new Exception("{$errno} - {$errstr}"); - } - } - - function __destruct() { - fclose($this->__sock); - } - - function __call($name, $args) { - - /* Build the Redis unified protocol command */ - array_unshift($args, strtoupper($name)); - $command = sprintf('*%d%s%s%s', count($args), CRLF, implode(array_map(array($this, 'formatArgument'), $args), CRLF), CRLF); - - /* Open a Redis connection and execute the command */ - $reconnects = 0; - for ($written = 0; $written < strlen($command); $written += $fwrite) { - $fwrite = @fwrite($this->__sock, substr($command, $written)); - if ($fwrite === FALSE || $fwrite === 0) { - if ($reconnects >= (int)$this->max_reconnects) { - throw new Exception('Failed to write entire command to stream'); - }else{ - fclose($this->__sock); - sleep(1); - $this->establishConnection(); - $reconnects++; - } - } - } - - /* Parse the response based on the reply identifier */ - $reply = trim(fgets($this->__sock, 512)); - switch (substr($reply, 0, 1)) { - /* Error reply */ - case '-': - throw new RedisException(substr(trim($reply), 4)); - break; - /* Inline reply */ - case '+': - $response = substr(trim($reply), 1); - break; - /* Bulk reply */ - case '$': - $response = null; - if ($reply == '$-1') { - break; - } - $read = 0; - $size = substr($reply, 1); - do { - $block_size = ($size - $read) > 1024 ? 1024 : ($size - $read); - $response .= fread($this->__sock, $block_size); - $read += $block_size; - } while ($read < $size); - fread($this->__sock, 2); /* discard crlf */ - break; - /* Multi-bulk reply */ - case '*': - $count = substr($reply, 1); - if ($count == '-1') { - return null; - } - $response = array(); - for ($i = 0; $i < $count; $i++) { - $bulk_head = trim(fgets($this->__sock, 512)); - $size = substr($bulk_head, 1); - if ($size == '-1') { - $response[] = null; - } - else { - $read = 0; - $block = ""; - do { - $block_size = ($size - $read) > 1024 ? 1024 : ($size - $read); - $block .= fread($this->__sock, $block_size); - $read += $block_size; - } while ($read < $size); - fread($this->__sock, 2); /* discard crlf */ - $response[] = $block; - } - } - break; - /* Integer reply */ - case ':': - $response = intval(substr(trim($reply), 1)); - break; - default: - throw new RedisException("invalid server response: {$reply}"); - break; - } - /* Party on */ - return $response; - } - - private function formatArgument($arg) { - return sprintf('$%d%s%s', strlen($arg), CRLF, $arg); - } -} \ No newline at end of file diff --git a/lib/Redisent/RedisentCluster.php b/lib/Redisent/RedisentCluster.php deleted file mode 100644 index 215726e..0000000 --- a/lib/Redisent/RedisentCluster.php +++ /dev/null @@ -1,138 +0,0 @@ - - * @copyright 2009 Justin Poliey - * @license http://www.opensource.org/licenses/mit-license.php The MIT License - * @package Redisent - */ - -require_once __DIR__ . '/Redisent.php'; - -/** - * A generalized Redisent interface for a cluster of Redis servers - */ -class RedisentCluster { - - /** - * Collection of Redisent objects attached to Redis servers - * @var array - * @access private - */ - private $redisents; - - /** - * Aliases of Redisent objects attached to Redis servers, used to route commands to specific servers - * @see RedisentCluster::to - * @var array - * @access private - */ - private $aliases; - - /** - * Hash ring of Redis server nodes - * @var array - * @access private - */ - private $ring; - - /** - * Individual nodes of pointers to Redis servers on the hash ring - * @var array - * @access private - */ - private $nodes; - - /** - * Number of replicas of each node to make around the hash ring - * @var integer - * @access private - */ - private $replicas = 128; - - /** - * The commands that are not subject to hashing - * @var array - * @access private - */ - private $dont_hash = array( - 'RANDOMKEY', 'DBSIZE', - 'SELECT', 'MOVE', 'FLUSHDB', 'FLUSHALL', - 'SAVE', 'BGSAVE', 'LASTSAVE', 'SHUTDOWN', - 'INFO', 'MONITOR', 'SLAVEOF' - ); - - /** - * Creates a Redisent interface to a cluster of Redis servers - * @param array $servers The Redis servers in the cluster. Each server should be in the format array('host' => hostname, 'port' => port) - */ - function __construct($servers) { - $this->ring = array(); - $this->aliases = array(); - foreach ($servers as $alias => $server) { - $this->redisents[] = new Redisent($server['host'], $server['port']); - if (is_string($alias)) { - $this->aliases[$alias] = $this->redisents[count($this->redisents)-1]; - } - for ($replica = 1; $replica <= $this->replicas; $replica++) { - $this->ring[crc32($server['host'].':'.$server['port'].'-'.$replica)] = $this->redisents[count($this->redisents)-1]; - } - } - ksort($this->ring, SORT_NUMERIC); - $this->nodes = array_keys($this->ring); - } - - /** - * Routes a command to a specific Redis server aliased by {$alias}. - * @param string $alias The alias of the Redis server - * @return Redisent The Redisent object attached to the Redis server - */ - function to($alias) { - if (isset($this->aliases[$alias])) { - return $this->aliases[$alias]; - } - else { - throw new Exception("That Redisent alias does not exist"); - } - } - - /* Execute a Redis command on the cluster */ - function __call($name, $args) { - - /* Pick a server node to send the command to */ - $name = strtoupper($name); - if (!in_array($name, $this->dont_hash)) { - $node = $this->nextNode(crc32($args[0])); - $redisent = $this->ring[$node]; - } - else { - $redisent = $this->redisents[0]; - } - - /* Execute the command on the server */ - return call_user_func_array(array($redisent, $name), $args); - } - - /** - * Routes to the proper server node - * @param integer $needle The hash value of the Redis command - * @return Redisent The Redisent object associated with the hash - */ - private function nextNode($needle) { - $haystack = $this->nodes; - while (count($haystack) > 2) { - $try = floor(count($haystack) / 2); - if ($haystack[$try] == $needle) { - return $needle; - } - if ($needle < $haystack[$try]) { - $haystack = array_slice($haystack, 0, $try + 1); - } - if ($needle > $haystack[$try]) { - $haystack = array_slice($haystack, $try + 1); - } - } - return $haystack[count($haystack)-1]; - } - -} \ No newline at end of file diff --git a/lib/Resque.php b/lib/Resque.php index c3254a3..88cec4c 100644 --- a/lib/Resque.php +++ b/lib/Resque.php @@ -71,21 +71,7 @@ class Resque $server = 'localhost:6379'; } - if(is_array($server)) { - self::$redis = new Resque_RedisCluster($server); - } - else { - if (strpos($server, 'unix:') === false) { - list($host, $port) = explode(':', $server); - } - else { - $host = $server; - $port = null; - } - self::$redis = new Resque_Redis($host, $port); - } - - self::$redis->select(self::$redisDatabase); + self::$redis = new Resque_Redis($server, self::$redisDatabase); return self::$redis; } diff --git a/lib/Resque/Redis.php b/lib/Resque/Redis.php index 1cff624..f6f6dc6 100644 --- a/lib/Resque/Redis.php +++ b/lib/Resque/Redis.php @@ -1,25 +1,22 @@ * @license http://www.opensource.org/licenses/mit-license.php */ -class Resque_Redis extends Redisent +class Resque_Redis { /** * Redis namespace * @var string */ private static $defaultNamespace = 'resque:'; + + private $server; + private $database; + /** * @var array List of all commands in Redis that supply a key as their * first argument. Used to prefix keys with the Resque namespace. @@ -81,7 +78,7 @@ class Resque_Redis extends Redisent // msetnx // mset // renamenx - + /** * Set Redis namespace (prefix) default: resque * @param string $namespace @@ -93,7 +90,36 @@ class Resque_Redis extends Redisent } self::$defaultNamespace = $namespace; } - + + public function __construct($server, $database = null) + { + $this->server = $server; + $this->database = $database; + + if (is_array($this->server)) { + $this->driver = new Credis_Cluster($server); + } + else { + $port = null; + $host = $server; + + // If not a UNIX socket path or tcp:// formatted connections string + // assume host:port combination. + if (strpos($server, '/') === false) { + $parts = explode(':', $server); + if (isset($parts[1])) { + $port = $parts[1]; + } + $host = $parts[0]; + } + $this->driver = new Credis_Client($host, $port); + } + + if ($this->database !== null) { + $this->driver->select($database); + } + } + /** * Magic method to handle all function requests and prefix key based * operations with the {self::$defaultNamespace} key prefix. @@ -103,14 +129,13 @@ class Resque_Redis extends Redisent * @return mixed Return value from Resident::call() based on the command. */ public function __call($name, $args) { - $args = func_get_args(); if(in_array($name, $this->keyCommands)) { - $args[1][0] = self::$defaultNamespace . $args[1][0]; + $args[0] = self::$defaultNamespace . $args[0]; } try { - return parent::__call($name, $args[1]); + return $this->driver->__call($name, $args); } - catch(RedisException $e) { + catch(CredisException $e) { return false; } } @@ -130,4 +155,4 @@ class Resque_Redis extends Redisent return $string; } } -?> +?> \ No newline at end of file diff --git a/lib/Resque/RedisCluster.php b/lib/Resque/RedisCluster.php deleted file mode 100644 index 21caeb7..0000000 --- a/lib/Resque/RedisCluster.php +++ /dev/null @@ -1,117 +0,0 @@ - - * @license http://www.opensource.org/licenses/mit-license.php - */ -class Resque_RedisCluster extends RedisentCluster -{ - /** - * Redis namespace - * @var string - */ - private static $defaultNamespace = 'resque:'; - /** - * @var array List of all commands in Redis that supply a key as their - * first argument. Used to prefix keys with the Resque namespace. - */ - private $keyCommands = array( - 'exists', - 'del', - 'type', - 'keys', - 'expire', - 'ttl', - 'move', - 'set', - 'get', - 'getset', - 'setnx', - 'incr', - 'incrby', - 'decrby', - 'decrby', - 'rpush', - 'lpush', - 'llen', - 'lrange', - 'ltrim', - 'lindex', - 'lset', - 'lrem', - 'lpop', - 'rpop', - 'sadd', - 'srem', - 'spop', - 'scard', - 'sismember', - 'smembers', - 'srandmember', - 'zadd', - 'zrem', - 'zrange', - 'zrevrange', - 'zrangebyscore', - 'zcard', - 'zscore', - 'zremrangebyscore', - 'sort' - ); - // sinterstore - // sunion - // sunionstore - // sdiff - // sdiffstore - // sinter - // smove - // rename - // rpoplpush - // mget - // msetnx - // mset - // renamenx - - /** - * Set Redis namespace (prefix) default: resque - * @param string $namespace - */ - public static function prefix($namespace) - { - if (strpos($namespace, ':') === false) { - $namespace .= ':'; - } - self::$defaultNamespace = $namespace; - } - - /** - * Magic method to handle all function requests and prefix key based - * operations with the '{self::$defaultNamespace}' key prefix. - * - * @param string $name The name of the method called. - * @param array $args Array of supplied arguments to the method. - * @return mixed Return value from Resident::call() based on the command. - */ - public function __call($name, $args) { - $args = func_get_args(); - if(in_array($name, $this->keyCommands)) { - $args[1][0] = self::$defaultNamespace . $args[1][0]; - } - try { - return parent::__call($name, $args[1]); - } - catch(RedisException $e) { - return false; - } - } -} -?> diff --git a/test/Resque/Tests/TestCase.php b/test/Resque/Tests/TestCase.php index 6c052d3..4ed65de 100644 --- a/test/Resque/Tests/TestCase.php +++ b/test/Resque/Tests/TestCase.php @@ -15,7 +15,7 @@ class Resque_Tests_TestCase extends PHPUnit_Framework_TestCase { $config = file_get_contents(REDIS_CONF); preg_match('#^\s*port\s+([0-9]+)#m', $config, $matches); - $this->redis = new Redisent('localhost', $matches[1]); + $this->redis = new Credis_Client('localhost', $matches[1]); // Flush redis $this->redis->flushAll(); From b0900d63902c30d370e3e8e211ece9131ca79378 Mon Sep 17 00:00:00 2001 From: Chris Boulton Date: Sat, 12 Jan 2013 23:56:16 +1100 Subject: [PATCH 27/37] add package suggestions (proctitle and redis extensions) --- composer.json | 4 ++++ composer.lock | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9b67eae..32f92ad 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,10 @@ "php": ">=5.3.0", "colinmollenhour/credis": "dev-master" }, + "suggest": { + "ext-proctitle": "Allows php-resque to rename the title of UNIX processes to show the status of a worker.", + "ext-redis": "Native PHP extension for Redis connectivity. Credis will automatically utilize when available." + }, "require-dev": { "phpunit/phpunit": "3.7.*" }, diff --git a/composer.lock b/composer.lock index 472226f..877c243 100644 --- a/composer.lock +++ b/composer.lock @@ -1,5 +1,5 @@ { - "hash": "af626b3a277bd0ab503c2c107327a88e", + "hash": "d37909ad0ffc11ed4d1e67dcaabe00b2", "packages": [ { "name": "colinmollenhour/credis", From ac28ca36d5e1e83361383aee215b912cbd0e3d33 Mon Sep 17 00:00:00 2001 From: Chris Boulton Date: Sun, 13 Jan 2013 01:06:32 +1100 Subject: [PATCH 28/37] test with and without phpredis extension --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index b1b8e8c..c78e442 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,5 +2,9 @@ language: php php: - 5.3 - 5.4 +env: + - REDIS_STANDALONE=0 + - REDIS_STANDALONE=1 before_script: + - sh -c "if [ $REDIS_STANDALONE -eq 0 ]; then pecl install redis && echo \"extension=redis.so\" >> `php --ini | grep \"Loaded Configuration\" | sed -e \"s|.*:\s*||\"`; fi" - composer install --dev \ No newline at end of file From ab9195cf19b1c4f5a9633589828e31231f6951f4 Mon Sep 17 00:00:00 2001 From: Chris Boulton Date: Sun, 13 Jan 2013 01:15:04 +1100 Subject: [PATCH 29/37] php-redis is not available via pecl, install using wget (not nice) --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index c78e442..e24a56f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,5 +6,7 @@ env: - REDIS_STANDALONE=0 - REDIS_STANDALONE=1 before_script: + - sh -c "if [ $REDIS_STANDALONE -eq 0 ]; then wget https://github.com/nicolasff/phpredis/archive/2.2.2.zip -O php-redis.zip && unzip php-redis.zip; fi" + - sh -c "if [ $REDIS_STANDALONE -eq 0 ]; then cd phpredis-2.2.2/ && phpize && ./configure && make && make install; fi" - sh -c "if [ $REDIS_STANDALONE -eq 0 ]; then pecl install redis && echo \"extension=redis.so\" >> `php --ini | grep \"Loaded Configuration\" | sed -e \"s|.*:\s*||\"`; fi" - composer install --dev \ No newline at end of file From f082ec872e317226622372bbbefd55b18e1e72b5 Mon Sep 17 00:00:00 2001 From: Chris Boulton Date: Sun, 13 Jan 2013 01:16:19 +1100 Subject: [PATCH 30/37] remove pecl install --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e24a56f..7e6faf6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,5 +8,5 @@ env: before_script: - sh -c "if [ $REDIS_STANDALONE -eq 0 ]; then wget https://github.com/nicolasff/phpredis/archive/2.2.2.zip -O php-redis.zip && unzip php-redis.zip; fi" - sh -c "if [ $REDIS_STANDALONE -eq 0 ]; then cd phpredis-2.2.2/ && phpize && ./configure && make && make install; fi" - - sh -c "if [ $REDIS_STANDALONE -eq 0 ]; then pecl install redis && echo \"extension=redis.so\" >> `php --ini | grep \"Loaded Configuration\" | sed -e \"s|.*:\s*||\"`; fi" + - sh -c "if [ $REDIS_STANDALONE -eq 0 ]; then echo \"extension=redis.so\" >> `php --ini | grep \"Loaded Configuration\" | sed -e \"s|.*:\s*||\"`; fi" - composer install --dev \ No newline at end of file From 6800fbe5ac8000c617f53c94a3621b74908f52e7 Mon Sep 17 00:00:00 2001 From: Chris Boulton Date: Sun, 13 Jan 2013 02:59:06 +1100 Subject: [PATCH 31/37] fix compatibility with phpredis * implement a fork helper method that closes the connection to redis before forking (instead of resetting after) to work around bugs with phpredis/socket fork handling * phpredis does not automatically typecast to string, so worker name must be typecasted when registering --- bin/resque | 2 +- lib/Resque.php | 43 ++++++++++++++++++++++++++++--------------- lib/Resque/Worker.php | 25 ++----------------------- 3 files changed, 31 insertions(+), 39 deletions(-) diff --git a/bin/resque b/bin/resque index 687f6c4..186e1ee 100644 --- a/bin/resque +++ b/bin/resque @@ -68,7 +68,7 @@ if(!empty($COUNT) && $COUNT > 1) { if($count > 1) { for($i = 0; $i < $count; ++$i) { - $pid = pcntl_fork(); + $pid = Resque::fork(); if($pid == -1) { die("Could not fork worker ".$i."\n"); } diff --git a/lib/Resque.php b/lib/Resque.php index 88cec4c..fa22ed1 100644 --- a/lib/Resque.php +++ b/lib/Resque.php @@ -26,12 +26,6 @@ class Resque */ protected static $redisDatabase = 0; - /** - * @var int PID of current process. Used to detect changes when forking - * and implement "thread" safety to avoid race conditions. - */ - protected static $pid = null; - /** * Given a host/port combination separated by a colon, set it as * the redis server that Resque will talk to. @@ -54,15 +48,7 @@ class Resque */ public static function redis() { - // Detect when the PID of the current process has changed (from a fork, etc) - // and force a reconnect to redis. - $pid = getmypid(); - if (self::$pid !== $pid) { - self::$redis = null; - self::$pid = $pid; - } - - if(!is_null(self::$redis)) { + if (self::$redis !== null) { return self::$redis; } @@ -75,6 +61,33 @@ class Resque return self::$redis; } + /** + * fork() helper method for php-resque that handles issues PHP socket + * and phpredis have with passing around sockets between child/parent + * processes. + * + * Will close connection to Redis before forking. + * + * @return int Return vars as per pcntl_fork() + */ + public static function fork() + { + if(!function_exists('pcntl_fork')) { + return -1; + } + + // Close the connection to Redis before forking. + // This is a workaround for issues phpredis has. + self::$redis = null; + + $pid = pcntl_fork(); + if($pid === -1) { + throw new RuntimeException('Unable to fork child worker.'); + } + + return $pid; + } + /** * Push a job to the end of a specific queue. If the queue does not * exist, then create it as well. diff --git a/lib/Resque/Worker.php b/lib/Resque/Worker.php index d103810..5dc678d 100644 --- a/lib/Resque/Worker.php +++ b/lib/Resque/Worker.php @@ -184,7 +184,7 @@ class Resque_Worker Resque_Event::trigger('beforeFork', $job); $this->workingOn($job); - $this->child = $this->fork(); + $this->child = Resque::fork(); // Forked and we're the child. Run the job. if ($this->child === 0 || $this->child === false) { @@ -286,27 +286,6 @@ class Resque_Worker return $queues; } - /** - * Attempt to fork a child process from the parent to run a job in. - * - * Return values are those of pcntl_fork(). - * - * @return int -1 if the fork failed, 0 for the forked child, the PID of the child for the parent. - */ - private function fork() - { - if(!function_exists('pcntl_fork')) { - return false; - } - - $pid = pcntl_fork(); - if($pid === -1) { - throw new RuntimeException('Unable to fork child worker.'); - } - - return $pid; - } - /** * Perform necessary actions to start a worker. */ @@ -474,7 +453,7 @@ class Resque_Worker */ public function registerWorker() { - Resque::redis()->sadd('workers', $this); + Resque::redis()->sadd('workers', (string)$this); Resque::redis()->set('worker:' . (string)$this . ':started', strftime('%a %b %d %H:%M:%S %Z %Y')); } From aae168392c928b276706374936530bf424d9869d Mon Sep 17 00:00:00 2001 From: Chris Boulton Date: Sun, 13 Jan 2013 03:02:53 +1100 Subject: [PATCH 32/37] just use built in phpunit on travis ci --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7e6faf6..cdb4478 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,4 +9,4 @@ before_script: - sh -c "if [ $REDIS_STANDALONE -eq 0 ]; then wget https://github.com/nicolasff/phpredis/archive/2.2.2.zip -O php-redis.zip && unzip php-redis.zip; fi" - sh -c "if [ $REDIS_STANDALONE -eq 0 ]; then cd phpredis-2.2.2/ && phpize && ./configure && make && make install; fi" - sh -c "if [ $REDIS_STANDALONE -eq 0 ]; then echo \"extension=redis.so\" >> `php --ini | grep \"Loaded Configuration\" | sed -e \"s|.*:\s*||\"`; fi" - - composer install --dev \ No newline at end of file + - composer install \ No newline at end of file From 762daf9f368ac4820d116d71a27687c692431e66 Mon Sep 17 00:00:00 2001 From: Jesse O'Brien Date: Mon, 21 Jan 2013 15:50:24 -0500 Subject: [PATCH 33/37] Extra check for vendor 3 folders up. Failure to check up *3* folders when running the binary from chrisboulton/php-resque/bin/ results in never finding the autoload file when it tries to load up the composer dependencies. --- bin/resque | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/resque b/bin/resque index 186e1ee..40c5589 100644 --- a/bin/resque +++ b/bin/resque @@ -4,6 +4,7 @@ // Find and initialize Composer $files = array( __DIR__ . '/../../vendor/autoload.php', + __DIR__ . '/../../../autoload.php', __DIR__ . '/../../../../autoload.php', __DIR__ . '/../vendor/autoload.php', ); From afd84de15577becf5b7636d54cc460a09188335d Mon Sep 17 00:00:00 2001 From: Carlos Viglietta Date: Wed, 6 Feb 2013 12:37:12 -0200 Subject: [PATCH 34/37] REDIS_BACKEND_DB env variable added It's enable the possibility of use a different db index on redis backend --- bin/resque | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/resque b/bin/resque index 186e1ee..be85f67 100644 --- a/bin/resque +++ b/bin/resque @@ -30,8 +30,12 @@ if(empty($QUEUE)) { } $REDIS_BACKEND = getenv('REDIS_BACKEND'); +$REDIS_BACKEND_DB = getenv('REDIS_BACKEND_DB'); if(!empty($REDIS_BACKEND)) { - Resque::setBackend($REDIS_BACKEND); + if (empty($REDIS_BACKEND_DB)) + Resque::setBackend($REDIS_BACKEND); + else + Resque::setBackend($REDIS_BACKEND, $REDIS_BACKEND_DB); } $logLevel = 0; From 4b2bbe492b5b71a0e7d3f8d82735018b901a8b0f Mon Sep 17 00:00:00 2001 From: Lee Boynton Date: Wed, 20 Feb 2013 16:25:14 +0000 Subject: [PATCH 35/37] Fix composer example --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2b94eac..8e11988 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ If you're not familiar with Composer, please see . { ... "require": { - "php": ">=5.3.0" + "chrisboulton/php-resque": "1.2.x" }, ... } @@ -370,4 +370,4 @@ Called after a job has been queued using the `Resque::enqueue` method. Arguments * maetl * Matt Heath * jjfrey -* scragg0x \ No newline at end of file +* scragg0x From 6a429c2f21174b5429f56871af22c07d19616291 Mon Sep 17 00:00:00 2001 From: TrimbleTodd Date: Wed, 20 Feb 2013 11:41:41 -0500 Subject: [PATCH 36/37] adding support for remote redis instances (such as redistogo) that require authentication --- lib/Resque/Redis.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/Resque/Redis.php b/lib/Resque/Redis.php index f6f6dc6..bbb0643 100644 --- a/lib/Resque/Redis.php +++ b/lib/Resque/Redis.php @@ -101,6 +101,7 @@ class Resque_Redis } else { $port = null; + $password = null; $host = $server; // If not a UNIX socket path or tcp:// formatted connections string @@ -111,8 +112,19 @@ class Resque_Redis $port = $parts[1]; } $host = $parts[0]; + }else if (strpos($server, 'redis://') !== false){ + // Redis format is: + // redis://[user]:[password]@[host]:[port] + list($userpwd,$hostport) = explode('@', $server); + $userpwd = substr($userpwd, strpos($userpwd, 'redis://')+8); + list($host, $port) = explode(':', $hostport); + list($user, $password) = explode(':', $userpwd); } + $this->driver = new Credis_Client($host, $port); + if (isset($password)){ + $this->driver->auth($password); + } } if ($this->database !== null) { From 3b4c46e039785b4b9cf40dd477321853a1638be7 Mon Sep 17 00:00:00 2001 From: Corey Ballou Date: Thu, 21 Feb 2013 07:37:16 -0500 Subject: [PATCH 37/37] Fixed the Resque_Worker log method to properly handle NORMAL vs VERBOSE logging. --- lib/Resque/Worker.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/Resque/Worker.php b/lib/Resque/Worker.php index 5dc678d..45852bb 100644 --- a/lib/Resque/Worker.php +++ b/lib/Resque/Worker.php @@ -169,7 +169,7 @@ class Resque_Worker break; } // If no job was found, we sleep for $interval before continuing and checking again - $this->log('Sleeping for ' . $interval, true); + $this->log('Sleeping for ' . $interval, self::LOG_VERBOSE); if($this->paused) { $this->updateProcLine('Paused'); } @@ -517,16 +517,21 @@ class Resque_Worker /** * Output a given log message to STDOUT. * - * @param string $message Message to output. + * @param string $message Message to output. + * @param int $logLevel The logging level to capture */ - public function log($message) + public function log($message, $logLevel = self::LOG_NORMAL) { - if($this->logLevel == self::LOG_NORMAL) { + if ($logLevel > $this->logLevel) { + return; + } + + if ($this->logLevel == self::LOG_NORMAL) { fwrite(STDOUT, "*** " . $message . "\n"); + return; } - else if($this->logLevel == self::LOG_VERBOSE) { - fwrite(STDOUT, "** [" . strftime('%T %Y-%m-%d') . "] " . $message . "\n"); - } + + fwrite(STDOUT, "** [" . strftime('%T %Y-%m-%d') . "] " . $message . "\n"); } /**