Skip to content

Commit 5687c8f

Browse files
committed
Merge branch 'master' of git://github.com/chrisboulton/php-resque into blocking-list-pop
Conflicts: lib/Resque.php lib/Resque/RedisCluster.php lib/Resque/Worker.php
2 parents 5eff86d + cd85e8b commit 5687c8f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+454
-766
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor/

.travis.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
language: php
22
php:
3-
- 5.2
43
- 5.3
54
- 5.4
5+
env:
6+
- REDIS_STANDALONE=0
7+
- REDIS_STANDALONE=1
8+
before_script:
9+
- 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"
10+
- sh -c "if [ $REDIS_STANDALONE -eq 0 ]; then cd phpredis-2.2.2/ && phpize && ./configure && make && make install; fi"
11+
- sh -c "if [ $REDIS_STANDALONE -eq 0 ]; then echo \"extension=redis.so\" >> `php --ini | grep \"Loaded Configuration\" | sed -e \"s|.*:\s*||\"`; fi"
12+
- composer install

CHANGELOG.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,35 @@
1-
## 1.2 (Unreleased) ##
1+
## 1.3 (2013-??-??) - Current Master ##
2+
3+
**Note:** This release introduces backwards incompatible changes with all previous versions of php-resque. Please see below for details.
4+
5+
### Redisent (Redis Library) Replaced with Credis
6+
7+
Redisent has always been the Redis backend for php-resque because of its lightweight nature. Unfortunately, Redisent is largely unmaintained.
8+
9+
[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)
10+
11+
php-resque now utilizes Credis for all Redis based operations. Credis automatically required and installed as a Composer dependency.
12+
13+
### Composer Support
14+
15+
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.
16+
17+
### Other Improvements/Changes
18+
19+
* **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.
20+
21+
* Restructure tests and test bootstrapping. Autoload tests via Composer (install test dependencies with `composer install --dev`)
22+
23+
* Add `SETEX` to list of commands which supply a key as the first argument in Redisent (danhunsaker)
24+
25+
* Fix an issue where a lost connection to Redis could cause an infinite loop (atorres757)
26+
27+
* Add a helper method to `Resque_Redis` to remove the namespace applied to Redis keys (tonypiper)
28+
29+
30+
## 1.2 (2012-10-13) ##
31+
32+
**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.
233

334
* Allow alternate redis database to be selected when calling setBackend by supplying a second argument (patrickbajao)
435
* 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 +41,17 @@
1041
* Fix lost jobs when there is more than one worker process started by the same parent process (salimane)
1142
* Move include for resque before APP_INCLUDE is loaded in, so that way resque is available for the app
1243
* Avoid working with dirty worker IDs (salimane)
13-
44+
* Allow UNIX socket to be passed to Resque when connecting to Redis (pedroarnal)
45+
* Fix typographical errors in PHP docblocks (chaitanyakuber)
46+
* Set the queue name on job instances when jobs are executed (chaitanyakuber)
47+
* Fix and add tests for Resque_Event::stopListening (ebernhardson)
48+
* Documentation cleanup (maetl)
49+
* Pass queue name to afterEvent callback
50+
* Only declare RedisException if it doesn't already exist (Matt Heath)
51+
* Add support for Composer
52+
* Fix missing and incorrect paths for Resque and Resque_Job_Status classes in demo (jjfrey)
53+
* Disable autoload for the RedisException class_exists call (scragg0x)
54+
* General tidy up of comments and files/folders
1455

1556
## 1.1 (2011-03-27) ##
1657

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(c) 2010 Chris Boulton <chris.boulton@interspire.com>
1+
(c) Chris Boulton <chris@bigcommerce.com>
22

33
Permission is hereby granted, free of charge, to any person obtaining
44
a copy of this software and associated documentation files (the

README.md

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,41 @@ pre and post jobs
3737

3838
## Requirements ##
3939

40-
* PHP 5.2+
40+
* PHP 5.3+
4141
* Redis 2.2+
42+
* Optional but Recommended: Composer
43+
44+
## Getting Started ##
45+
46+
The easiest way to work with php-resque is when it's installed as a
47+
Composer package inside your project. Composer isn't strictly
48+
required, but makes life a lot easier.
49+
50+
If you're not familiar with Composer, please see <http://getcomposer.org/>.
51+
52+
1. Add php-resque to your application's composer.json.
53+
54+
{
55+
...
56+
"require": {
57+
"chrisboulton/php-resque": "1.2.x"
58+
},
59+
...
60+
}
61+
62+
2. Run `composer install`.
63+
64+
3. If you haven't already, add the Composer autoload to your project's
65+
initialization file. (example)
66+
67+
require 'vendor/autoload.php';
4268

4369
## Jobs ##
4470

4571
### Queueing Jobs ###
4672

4773
Jobs are queued as follows:
4874

49-
require_once 'lib/Resque.php';
50-
5175
// Required if redis is located elsewhere
5276
Resque::setBackend('localhost:6379');
5377

@@ -87,12 +111,12 @@ The `tearDown` method if defined, will be called after the job finishes.
87111
{
88112
// ... Set up environment for this job
89113
}
90-
114+
91115
public function perform()
92116
{
93117
// .. Run job
94118
}
95-
119+
96120
public function tearDown()
97121
{
98122
// ... Remove environment for this job
@@ -136,8 +160,9 @@ class.
136160
Workers work in the exact same way as the Ruby workers. For complete
137161
documentation on workers, see the original documentation.
138162

139-
A basic "up-and-running" resque.php file is included that sets up a
140-
running worker environment is included in the root directory.
163+
A basic "up-and-running" `bin/resque` file is included that sets up a
164+
running worker environment is included. (`vendor/bin/resque` when installed
165+
via Composer)
141166

142167
The exception to the similarities with the Ruby version of resque is
143168
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
146171

147172
To start a worker, it's very similar to the Ruby version:
148173

149-
$ QUEUE=file_serve php resque.php
174+
$ QUEUE=file_serve php bin/resque
150175

151176
It's your responsibility to tell the worker which file to include to get
152177
your application underway. You do so by setting the `APP_INCLUDE` environment
153178
variable:
154179

155-
$ QUEUE=file_serve APP_INCLUDE=../application/init.php php resque.php
180+
$ QUEUE=file_serve APP_INCLUDE=../application/init.php php bin/resque
181+
182+
*Pro tip: Using Composer? More than likely, you don't need to worry about
183+
`APP_INCLUDE`, because hopefully Composer is responsible for autoloading
184+
your application too!*
156185

157186
Getting your application underway also includes telling the worker your job
158187
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.
163192
Setting `VERBOSE` will print basic debugging information and `VVERBOSE`
164193
will print detailed information.
165194

166-
$ VERBOSE QUEUE=file_serve php resque.php
167-
$ VVERBOSE QUEUE=file_serve php resque.php
195+
$ VERBOSE QUEUE=file_serve bin/resque
196+
$ VVERBOSE QUEUE=file_serve bin/resque
168197

169198
### Priorities and Queue Lists ###
170199

@@ -175,7 +204,7 @@ checked in.
175204

176205
As per the original example:
177206

178-
$ QUEUE=file_serve,warm_cache php resque.php
207+
$ QUEUE=file_serve,warm_cache bin/resque
179208

180209
The `file_serve` queue will always be checked for new jobs on each
181210
iteration before the `warm_cache` queue is checked.
@@ -185,14 +214,14 @@ iteration before the `warm_cache` queue is checked.
185214
All queues are supported in the same manner and processed in alphabetical
186215
order:
187216

188-
$ QUEUE=* php resque.php
217+
$ QUEUE=* bin/resque
189218

190219
### Running Multiple Workers ###
191220

192221
Multiple workers ca be launched and automatically worked by supplying
193222
the `COUNT` environment variable:
194223

195-
$ COUNT=5 php resque.php
224+
$ COUNT=5 bin/resque
196225

197226
### Forking ###
198227

@@ -257,7 +286,7 @@ It is up to your application to register event listeners. When enqueuing events
257286
in your application, it should be as easy as making sure php-resque is loaded
258287
and calling `Resque_Event::listen`.
259288

260-
When running workers, if you run workers via the default `resque.php` script,
289+
When running workers, if you run workers via the default `bin/resque` script,
261290
your `APP_INCLUDE` script should initialize and register any listeners required
262291
for operation. If you have rolled your own worker manager, then it is again your
263292
responsibility to register listeners.
@@ -329,3 +358,16 @@ Called after a job has been queued using the `Resque::enqueue` method. Arguments
329358
* KevBurnsJr
330359
* jmathai
331360
* dceballos
361+
* patrickbajao
362+
* andrewjshults
363+
* warezthebeef
364+
* d11wtq
365+
* hlegius
366+
* salimane
367+
* humancopy
368+
* pedroarnal
369+
* chaitanyakuber
370+
* maetl
371+
* Matt Heath
372+
* jjfrey
373+
* scragg0x

TODO.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

bin/resque

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,106 @@
1-
#!/bin/sh
1+
#!/usr/bin/env php
2+
<?php
3+
4+
// Find and initialize Composer
5+
$files = array(
6+
__DIR__ . '/../../vendor/autoload.php',
7+
__DIR__ . '/../../../autoload.php',
8+
__DIR__ . '/../../../../autoload.php',
9+
__DIR__ . '/../vendor/autoload.php',
10+
);
11+
12+
$found = false;
13+
foreach ($files as $file) {
14+
if (file_exists($file)) {
15+
require_once $file;
16+
break;
17+
}
18+
}
19+
20+
if (!class_exists('Composer\Autoload\ClassLoader', false)) {
21+
die(
22+
'You need to set up the project dependencies using the following commands:' . PHP_EOL .
23+
'curl -s http://getcomposer.org/installer | php' . PHP_EOL .
24+
'php composer.phar install' . PHP_EOL
25+
);
26+
}
27+
28+
$QUEUE = getenv('QUEUE');
29+
if(empty($QUEUE)) {
30+
die("Set QUEUE env var containing the list of queues to work.\n");
31+
}
32+
33+
$REDIS_BACKEND = getenv('REDIS_BACKEND');
34+
$REDIS_BACKEND_DB = getenv('REDIS_BACKEND_DB');
35+
if(!empty($REDIS_BACKEND)) {
36+
if (empty($REDIS_BACKEND_DB))
37+
Resque::setBackend($REDIS_BACKEND);
38+
else
39+
Resque::setBackend($REDIS_BACKEND, $REDIS_BACKEND_DB);
40+
}
41+
42+
$logLevel = 0;
43+
$LOGGING = getenv('LOGGING');
44+
$VERBOSE = getenv('VERBOSE');
45+
$VVERBOSE = getenv('VVERBOSE');
46+
if(!empty($LOGGING) || !empty($VERBOSE)) {
47+
$logLevel = Resque_Worker::LOG_NORMAL;
48+
}
49+
else if(!empty($VVERBOSE)) {
50+
$logLevel = Resque_Worker::LOG_VERBOSE;
51+
}
52+
53+
$APP_INCLUDE = getenv('APP_INCLUDE');
54+
if($APP_INCLUDE) {
55+
if(!file_exists($APP_INCLUDE)) {
56+
die('APP_INCLUDE ('.$APP_INCLUDE.") does not exist.\n");
57+
}
58+
59+
require_once $APP_INCLUDE;
60+
}
61+
62+
$interval = 5;
63+
$INTERVAL = getenv('INTERVAL');
64+
if(!empty($INTERVAL)) {
65+
$interval = $INTERVAL;
66+
}
67+
68+
$count = 1;
69+
$COUNT = getenv('COUNT');
70+
if(!empty($COUNT) && $COUNT > 1) {
71+
$count = $COUNT;
72+
}
73+
74+
if($count > 1) {
75+
for($i = 0; $i < $count; ++$i) {
76+
$pid = Resque::fork();
77+
if($pid == -1) {
78+
die("Could not fork worker ".$i."\n");
79+
}
80+
// Child, start the worker
81+
else if(!$pid) {
82+
$queues = explode(',', $QUEUE);
83+
$worker = new Resque_Worker($queues);
84+
$worker->logLevel = $logLevel;
85+
fwrite(STDOUT, '*** Starting worker '.$worker."\n");
86+
$worker->work($interval);
87+
break;
88+
}
89+
}
90+
}
91+
// Start a single worker
92+
else {
93+
$queues = explode(',', $QUEUE);
94+
$worker = new Resque_Worker($queues);
95+
$worker->logLevel = $logLevel;
96+
97+
$PIDFILE = getenv('PIDFILE');
98+
if ($PIDFILE) {
99+
file_put_contents($PIDFILE, getmypid()) or
100+
die('Could not write PID information to ' . $PIDFILE);
101+
}
102+
103+
fwrite(STDOUT, '*** Starting worker '.$worker."\n");
104+
$worker->work($interval);
105+
}
106+
?>

composer.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,26 @@
1111
"email": "[email protected]"
1212
}
1313
],
14+
"repositories": [
15+
{
16+
"type": "vcs",
17+
"url": "https://github.com/chrisboulton/credis"
18+
}
19+
],
1420
"require": {
15-
"php": ">=5.3.0"
21+
"php": ">=5.3.0",
22+
"colinmollenhour/credis": "dev-master"
1623
},
24+
"suggest": {
25+
"ext-proctitle": "Allows php-resque to rename the title of UNIX processes to show the status of a worker.",
26+
"ext-redis": "Native PHP extension for Redis connectivity. Credis will automatically utilize when available."
27+
},
28+
"require-dev": {
29+
"phpunit/phpunit": "3.7.*"
30+
},
31+
"bin": [
32+
"bin/resque"
33+
],
1734
"autoload": {
1835
"psr-0": {
1936
"Resque": "lib"

0 commit comments

Comments
 (0)