@@ -52,14 +52,13 @@ If you're not familiar with Composer, please see <http://getcomposer.org/>.
52
52
1 . Add php-resque to your application's composer.json.
53
53
54
54
``` json
55
-
56
- {
57
- ...
58
- "require" : {
59
- "chrisboulton/php-resque" : " 1.2.x"
60
- },
61
- ...
62
- }
55
+ {
56
+ //...
57
+ "require" : {
58
+ "chrisboulton/php-resque" : " 1.2.x"
59
+ },
60
+ // ...
61
+ }
63
62
```
64
63
65
64
2 . Run ` composer install ` .
@@ -68,7 +67,7 @@ If you're not familiar with Composer, please see <http://getcomposer.org/>.
68
67
initialization file. (example)
69
68
70
69
``` sh
71
- require ' vendor/autoload.php' ;
70
+ require ' vendor/autoload.php' ;
72
71
```
73
72
74
73
## Jobs ##
@@ -78,32 +77,28 @@ If you're not familiar with Composer, please see <http://getcomposer.org/>.
78
77
Jobs are queued as follows:
79
78
80
79
``` php
80
+ // Required if redis is located elsewhere
81
+ Resque::setBackend('localhost:6379');
81
82
82
- // Required if redis is located elsewhere
83
- Resque::setBackend('localhost:6379');
84
-
85
- $args = array(
86
- 'name' => 'Chris'
87
- );
88
- Resque::enqueue('default', 'My_Job', $args);
89
-
83
+ $args = array(
84
+ 'name' => 'Chris'
85
+ );
86
+ Resque::enqueue('default', 'My_Job', $args);
90
87
```
91
88
92
89
### Defining Jobs ###
93
90
94
91
Each job should be in it's own class, and include a ` perform ` method.
95
92
96
93
``` php
97
-
98
- class My_Job
99
- {
100
- public function perform()
101
- {
102
- // Work work work
103
- echo $this->args['name'];
104
- }
105
- }
106
-
94
+ class My_Job
95
+ {
96
+ public function perform()
97
+ {
98
+ // Work work work
99
+ echo $this->args['name'];
100
+ }
101
+ }
107
102
```
108
103
109
104
When the job is run, the class will be instantiated and any arguments
@@ -120,24 +115,23 @@ The `tearDown` method if defined, will be called after the job finishes.
120
115
121
116
122
117
``` php
118
+ class My_Job
119
+ {
120
+ public function setUp()
121
+ {
122
+ // ... Set up environment for this job
123
+ }
124
+
125
+ public function perform()
126
+ {
127
+ // .. Run job
128
+ }
123
129
124
- class My_Job
130
+ public function tearDown()
125
131
{
126
- public function setUp()
127
- {
128
- // ... Set up environment for this job
129
- }
130
-
131
- public function perform()
132
- {
133
- // .. Run job
134
- }
135
-
136
- public function tearDown()
137
- {
138
- // ... Remove environment for this job
139
- }
132
+ // ... Remove environment for this job
140
133
}
134
+ }
141
135
```
142
136
143
137
### Tracking Job Statuses ###
@@ -151,15 +145,15 @@ To track the status of a job, pass `true` as the fourth argument to
151
145
returned:
152
146
153
147
``` php
154
- $token = Resque::enqueue('default', 'My_Job', $args, true);
155
- echo $token;
148
+ $token = Resque::enqueue('default', 'My_Job', $args, true);
149
+ echo $token;
156
150
```
157
151
158
152
To fetch the status of a job:
159
153
160
154
``` php
161
- $status = new Resque_Job_Status($token);
162
- echo $status->get(); // Outputs the status
155
+ $status = new Resque_Job_Status($token);
156
+ echo $status->get(); // Outputs the status
163
157
```
164
158
165
159
Job statuses are defined as constants in the ` Resque_Job_Status ` class.
@@ -191,15 +185,15 @@ not having a single environment such as with Ruby, the PHP port makes
191
185
* no* assumptions about your setup.
192
186
193
187
To start a worker, it's very similar to the Ruby version:
194
-
195
- $ QUEUE=file_serve php bin/resque
196
-
188
+ ``` sh
189
+ $ QUEUE=file_serve php bin/resque
190
+ ```
197
191
It's your responsibility to tell the worker which file to include to get
198
192
your application underway. You do so by setting the ` APP_INCLUDE ` environment
199
193
variable:
200
194
201
195
``` sh
202
- $ QUEUE=file_serve APP_INCLUDE=../application/init.php php bin/resque
196
+ $ QUEUE=file_serve APP_INCLUDE=../application/init.php php bin/resque
203
197
```
204
198
205
199
* Pro tip: Using Composer? More than likely, you don't need to worry about
@@ -216,8 +210,8 @@ Setting `VERBOSE` will print basic debugging information and `VVERBOSE`
216
210
will print detailed information.
217
211
218
212
``` sh
219
- $ VERBOSE QUEUE=file_serve bin/resque
220
- $ VVERBOSE QUEUE=file_serve bin/resque
213
+ $ VERBOSE QUEUE=file_serve bin/resque
214
+ $ VVERBOSE QUEUE=file_serve bin/resque
221
215
```
222
216
223
217
### Priorities and Queue Lists ###
@@ -230,7 +224,7 @@ checked in.
230
224
As per the original example:
231
225
232
226
``` sh
233
- $ QUEUE=file_serve,warm_cache bin/resque
227
+ $ QUEUE=file_serve,warm_cache bin/resque
234
228
```
235
229
236
230
The ` file_serve ` queue will always be checked for new jobs on each
@@ -242,7 +236,7 @@ All queues are supported in the same manner and processed in alphabetical
242
236
order:
243
237
244
238
``` sh
245
- $ QUEUE=* bin/resque
239
+ $ QUEUE=* bin/resque
246
240
```
247
241
248
242
### Running Multiple Workers ###
@@ -251,7 +245,7 @@ Multiple workers ca be launched and automatically worked by supplying
251
245
the ` COUNT ` environment variable:
252
246
253
247
``` sh
254
- $ COUNT=5 bin/resque
248
+ $ COUNT=5 bin/resque
255
249
```
256
250
257
251
### Custom prefix ###
@@ -260,7 +254,7 @@ When you have multiple apps using the same Redis database it is better to
260
254
use a custom prefix to separate the Resque data:
261
255
262
256
``` sh
263
- $ PREFIX=my-app-name bin/resque
257
+ $ PREFIX=my-app-name bin/resque
264
258
```
265
259
266
260
### Forking ###
@@ -308,7 +302,7 @@ and supplying a callback that you would like triggered when the event is
308
302
raised:
309
303
310
304
``` sh
311
- Resque_Event::listen(' eventName' , [callback]);
305
+ Resque_Event::listen(' eventName' , [callback]);
312
306
```
313
307
314
308
` [callback] ` may be anything in PHP that is callable by ` call_user_func_array ` :
0 commit comments