1
+ <?php
2
+ // Find and initialize Composer
3
+ $ files = array (
4
+ __DIR__ . '/../../vendor/autoload.php ' ,
5
+ __DIR__ . '/../../../autoload.php ' ,
6
+ __DIR__ . '/../../../../autoload.php ' ,
7
+ __DIR__ . '/../vendor/autoload.php ' ,
8
+ );
9
+
10
+ $ found = false ;
11
+ foreach ($ files as $ file ) {
12
+ if (file_exists ($ file )) {
13
+ require_once $ file ;
14
+ break ;
15
+ }
16
+ }
17
+
18
+ if (!class_exists ('Composer\Autoload\ClassLoader ' , false )) {
19
+ die (
20
+ 'You need to set up the project dependencies using the following commands: ' . PHP_EOL .
21
+ 'curl -s http://getcomposer.org/installer | php ' . PHP_EOL .
22
+ 'php composer.phar install ' . PHP_EOL
23
+ );
24
+ }
25
+
26
+ $ QUEUE = getenv ('QUEUE ' );
27
+ if (empty ($ QUEUE )) {
28
+ die ("Set QUEUE env var containing the list of queues to work. \n" );
29
+ }
30
+
31
+ $ REDIS_BACKEND = getenv ('REDIS_BACKEND ' );
32
+ $ REDIS_BACKEND_DB = getenv ('REDIS_BACKEND_DB ' );
33
+ if (!empty ($ REDIS_BACKEND )) {
34
+ if (empty ($ REDIS_BACKEND_DB ))
35
+ Resque::setBackend ($ REDIS_BACKEND );
36
+ else
37
+ Resque::setBackend ($ REDIS_BACKEND , $ REDIS_BACKEND_DB );
38
+ }
39
+
40
+ $ logLevel = 0 ;
41
+ $ LOGGING = getenv ('LOGGING ' );
42
+ $ VERBOSE = getenv ('VERBOSE ' );
43
+ $ VVERBOSE = getenv ('VVERBOSE ' );
44
+ if (!empty ($ LOGGING ) || !empty ($ VERBOSE )) {
45
+ $ logLevel = Resque_Worker::LOG_NORMAL ;
46
+ }
47
+ else if (!empty ($ VVERBOSE )) {
48
+ $ logLevel = Resque_Worker::LOG_VERBOSE ;
49
+ }
50
+
51
+ $ BLOCKING = getenv ('BLOCKING ' ) !== FALSE ;
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 , $ BLOCKING );
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 , $ BLOCKING );
105
+ }
0 commit comments