1 | <?php |
||
11 | class Connection extends ClientConnection |
||
12 | { |
||
13 | /** |
||
14 | * Magic code for request |
||
15 | */ |
||
16 | const MAGIC_REQUEST = "\0REQ"; |
||
17 | |||
18 | /** |
||
19 | * Magic code for response |
||
20 | */ |
||
21 | const MAGIC_RESPONSE = "\0RES"; |
||
22 | |||
23 | /* |
||
24 | * Byte length of header |
||
25 | */ |
||
26 | const HEADER_LENGTH = 12; |
||
27 | |||
28 | /** |
||
29 | * Header binary format |
||
30 | */ |
||
31 | const HEADER_WRITE_FORMAT = "a4NN"; |
||
32 | |||
33 | /** |
||
34 | * Header read format |
||
35 | */ |
||
36 | const HEADER_READ_FORMAT = "a4magic/Ntype/Nsize"; |
||
37 | |||
38 | /** |
||
39 | * Delimeter for function arguments |
||
40 | */ |
||
41 | const ARGS_DELIMITER = "\0"; |
||
42 | |||
43 | |||
44 | /** |
||
45 | * Request codes |
||
46 | * |
||
47 | * @var array |
||
48 | */ |
||
49 | protected static $requestCommandList = [ |
||
50 | 'CAN_DO' => 1, |
||
51 | 'CANT_DO' => 2, |
||
52 | 'RESET_ABILITIES' => 3, |
||
53 | 'PRE_SLEEP' => 4, |
||
54 | 'SUBMIT_JOB' => 7, |
||
55 | 'GRAB_JOB' => 9, |
||
56 | 'WORK_STATUS' => 12, |
||
57 | 'WORK_COMPLETE' => 13, |
||
58 | 'WORK_FAIL' => 14, |
||
59 | 'GET_STATUS' => 15, |
||
60 | 'ECHO_REQ' => 16, |
||
61 | 'SUBMIT_JOB_BG' => 18, |
||
62 | 'SUBMIT_JOB_HIGH' => 21, |
||
63 | 'SET_CLIENT_ID' => 22, |
||
64 | 'CAN_DO_TIMEOUT' => 23, |
||
65 | 'ALL_YOURS' => 24, |
||
66 | 'WORK_EXCEPTION' => 25, |
||
67 | 'OPTION_REQ' => 26, |
||
68 | 'OPTION_RES' => 27, |
||
69 | 'WORK_DATA' => 28, |
||
70 | 'WORK_WARNING' => 29, |
||
71 | 'GRAB_JOB_UNIQ' => 30, |
||
72 | 'SUBMIT_JOB_HIGH_BG' => 32, |
||
73 | 'SUBMIT_JOB_LOW' => 33, |
||
74 | 'SUBMIT_JOB_LOW_BG' => 34, |
||
75 | 'SUBMIT_JOB_SCHED' => 35, |
||
76 | 'SUBMIT_JOB_EPOCH' => 36, |
||
77 | ]; |
||
78 | protected static $requestCommandListFlipped; |
||
79 | |||
80 | /** |
||
81 | * Response codes |
||
82 | * |
||
83 | * @var array |
||
84 | */ |
||
85 | protected static $responseCommandList = [ |
||
86 | 'NOOP' => 6, |
||
87 | 'JOB_CREATED' => 8, |
||
88 | 'NO_JOB' => 10, |
||
89 | 'JOB_ASSIGN' => 11, |
||
90 | 'WORK_STATUS' => 12, |
||
91 | 'WORK_COMPLETE' => 13, |
||
92 | 'WORK_FAIL' => 14, |
||
93 | 'ECHO_RES' => 17, |
||
94 | 'ERROR' => 19, |
||
95 | 'STATUS_RES' => 20, |
||
96 | 'WORK_EXCEPTION' => 25, |
||
97 | 'OPTION_RES' => 27, |
||
98 | 'WORK_WARNING' => 29, |
||
99 | 'JOB_ASSIGN_UNIQ' => 31, |
||
100 | ]; |
||
101 | |||
102 | protected static $responseCommandListFlipped; |
||
103 | |||
104 | /** |
||
105 | * @var mixed |
||
106 | */ |
||
107 | public $response; |
||
108 | |||
109 | /** |
||
110 | * @var string |
||
111 | */ |
||
112 | public $responseType; |
||
113 | |||
114 | /** |
||
115 | * @var string |
||
116 | */ |
||
117 | public $responseCommand; |
||
118 | |||
119 | /** |
||
120 | * Called when new data received |
||
121 | * |
||
122 | * @return void |
||
123 | */ |
||
124 | public function onRead() |
||
153 | |||
154 | /** |
||
155 | * Called when the connection is handshaked (at low-level), and peer is ready to recv. data |
||
156 | * @return void |
||
157 | */ |
||
158 | public function onReady() |
||
168 | |||
169 | |||
170 | /** |
||
171 | * Function send ECHO |
||
172 | * |
||
173 | * @param $payload |
||
174 | * @param callable|null $cb |
||
175 | */ |
||
176 | public function sendEcho($payload, $cb = null) |
||
180 | |||
181 | /** |
||
182 | * Send a command |
||
183 | * |
||
184 | * @param $commandName |
||
185 | * @param $payload |
||
186 | * @param callable $cb = null |
||
187 | */ |
||
188 | public function sendCommand($commandName, $payload, $cb = null) |
||
208 | |||
209 | /** |
||
210 | * Function run task and wait result in callback |
||
211 | * |
||
212 | * @param $params |
||
213 | * @param callable $cb = null |
||
214 | * @param boolean $unique |
||
215 | */ |
||
216 | public function submitJob($params, $cb = null) |
||
240 | |||
241 | /** |
||
242 | * Get job status |
||
243 | * |
||
244 | * @param mixed $jobHandle Job handle that was given in JOB_CREATED packet. |
||
245 | * @param callable $cb = null |
||
246 | * |
||
247 | */ |
||
248 | public function getStatus($jobHandle, $cb = null) |
||
252 | |||
253 | /** |
||
254 | * Function set settings for current connection |
||
255 | * Available settings |
||
256 | * 'exceptions' - Forward WORK_EXCEPTION packets to the client. |
||
257 | * |
||
258 | * @url http://gearman.org/protocol/ |
||
259 | * |
||
260 | * |
||
261 | * @param int $optionName |
||
262 | * @param callable $cb = null |
||
263 | */ |
||
264 | public function setConnectionOption($optionName, $cb = null) |
||
268 | } |
||
269 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.