@@ -12,6 +12,6 @@ |
||
12 | 12 | namespace MultiHttp\Exception; |
13 | 13 | |
14 | 14 | |
15 | -class InvalidOperationException extends \LogicException{ |
|
15 | +class InvalidOperationException extends \LogicException { |
|
16 | 16 | protected $code = 2; |
17 | 17 | } |
18 | 18 | \ No newline at end of file |
@@ -12,6 +12,6 @@ |
||
12 | 12 | namespace MultiHttp\Exception; |
13 | 13 | |
14 | 14 | |
15 | -class InvalidArgumentException extends \LogicException{ |
|
15 | +class InvalidArgumentException extends \LogicException { |
|
16 | 16 | protected $code = 1; |
17 | 17 | } |
18 | 18 | \ No newline at end of file |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | { |
34 | 34 | } |
35 | 35 | |
36 | - public static function create(Request $request, $body, $info, $errorCode, $error){ |
|
36 | + public static function create(Request $request, $body, $info, $errorCode, $error) { |
|
37 | 37 | $self = new self; |
38 | 38 | $self->request = $request; |
39 | 39 | $self->body = $body; |
@@ -44,21 +44,21 @@ discard block |
||
44 | 44 | $self->check(); |
45 | 45 | return $self; |
46 | 46 | } |
47 | - public function check(){ |
|
47 | + public function check() { |
|
48 | 48 | |
49 | 49 | } |
50 | - public function parse(){ |
|
50 | + public function parse() { |
|
51 | 51 | //has header |
52 | - if($this->request->getIni('header')){ |
|
52 | + if ($this->request->getIni('header')) { |
|
53 | 53 | $headers = rtrim(substr($this->body, 0, $this->info['header_size'])); |
54 | 54 | $this->body = substr($this->body, $this->info['header_size']); |
55 | 55 | $headers = explode(PHP_EOL, $headers); |
56 | 56 | array_shift($headers); // HTTP HEADER |
57 | - foreach($headers as $h) { |
|
58 | - if(false !== strpos($h, ':')) |
|
57 | + foreach ($headers as $h) { |
|
58 | + if (false !== strpos($h, ':')) |
|
59 | 59 | list($k, $v) = explode(':', $h, 2); |
60 | 60 | else |
61 | - list($k, $v) = array($h,''); |
|
61 | + list($k, $v) = array($h, ''); |
|
62 | 62 | |
63 | 63 | $this->header[trim($k)] = trim($v); |
64 | 64 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | $content_type = explode(';', $content_type); |
71 | 71 | $this->contentType = $content_type[0]; |
72 | 72 | if (count($content_type) == 2 && strpos($content_type[1], '=') !== false) { |
73 | - list( , $this->charset) = explode('=', $content_type[1]); |
|
73 | + list(, $this->charset) = explode('=', $content_type[1]); |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 |
@@ -13,24 +13,24 @@ |
||
13 | 13 | |
14 | 14 | trait RequestTrait { |
15 | 15 | protected $expectContentType = null; |
16 | - public function expectsJson(){ |
|
16 | + public function expectsJson() { |
|
17 | 17 | $this->expectContentType = Mime::JSON; |
18 | 18 | } |
19 | - public function expectsXml(){ |
|
19 | + public function expectsXml() { |
|
20 | 20 | $this->expectContentType = Mime::XML; |
21 | 21 | } |
22 | 22 | |
23 | - protected function json(){ |
|
23 | + protected function json() { |
|
24 | 24 | |
25 | 25 | } |
26 | - protected function unJson(){ |
|
26 | + protected function unJson() { |
|
27 | 27 | |
28 | 28 | } |
29 | 29 | |
30 | - protected function xml(){ |
|
30 | + protected function xml() { |
|
31 | 31 | |
32 | 32 | } |
33 | - protected function unXml(){ |
|
33 | + protected function unXml() { |
|
34 | 34 | |
35 | 35 | } |
36 | 36 | } |
@@ -51,15 +51,15 @@ |
||
51 | 51 | public function unJson($body) |
52 | 52 | { |
53 | 53 | $parsed = json_decode($body, true); |
54 | - if(json_last_error() !== JSON_ERROR_NONE)throw new UnexpectedResponseException('parsing json occurs error: '. self::jsonLastErrorMsg() . ', raw body: ' .$body ); |
|
54 | + if (json_last_error() !== JSON_ERROR_NONE)throw new UnexpectedResponseException('parsing json occurs error: '.self::jsonLastErrorMsg().', raw body: '.$body); |
|
55 | 55 | return $parsed; |
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
59 | 59 | * @return string |
60 | 60 | */ |
61 | - private static function jsonLastErrorMsg(){ |
|
62 | - if(function_exists('json_last_error_msg')) return json_last_error_msg(); |
|
61 | + private static function jsonLastErrorMsg() { |
|
62 | + if (function_exists('json_last_error_msg')) return json_last_error_msg(); |
|
63 | 63 | switch (json_last_error()) { |
64 | 64 | case JSON_ERROR_NONE: |
65 | 65 | return ' - No errors'; |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | protected static $curlAlias = array( |
20 | 20 | 'url' => 'CURLOPT_URL', |
21 | 21 | 'uri' => 'CURLOPT_URL', |
22 | - 'debug' => 'CURLOPT_VERBOSE',//for debug verbose |
|
22 | + 'debug' => 'CURLOPT_VERBOSE', //for debug verbose |
|
23 | 23 | 'method' => 'CURLOPT_CUSTOMREQUEST', |
24 | 24 | 'data' => 'CURLOPT_POSTFIELDS', // array or string , file begin with '@' |
25 | 25 | 'ua' => 'CURLOPT_USERAGENT', |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | 'follow_location' => true, |
63 | 63 | 'timeout' => 0, |
64 | 64 | // 'ip' => null, //host, in string, .e.g: 172.16.1.1:888 |
65 | - 'retry_times' => 1,//redo task when failed |
|
66 | - 'retry_duration' => 0,//in seconds |
|
65 | + 'retry_times' => 1, //redo task when failed |
|
66 | + 'retry_duration' => 0, //in seconds |
|
67 | 67 | ); |
68 | 68 | protected $endCallback; |
69 | 69 | protected $withURIQuery; |
@@ -254,9 +254,9 @@ discard block |
||
254 | 254 | } |
255 | 255 | /* no body */ |
256 | 256 | |
257 | - protected function ini($method, $url, $data , array $options = array()) |
|
257 | + protected function ini($method, $url, $data, array $options = array()) |
|
258 | 258 | { |
259 | - $options = array('url' => $url, 'method' => $method, 'data' => $data) + $options; |
|
259 | + $options = array('url' => $url, 'method' => $method, 'data' => $data)+$options; |
|
260 | 260 | $this->addOptions($options); |
261 | 261 | |
262 | 262 | return $this; |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | |
265 | 265 | public function addOptions(array $options = array()) |
266 | 266 | { |
267 | - $this->options = $options + $this->options; |
|
267 | + $this->options = $options+$this->options; |
|
268 | 268 | $this->uri = $this->options['url']; |
269 | 269 | return $this; |
270 | 270 | } |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | } |
356 | 356 | |
357 | 357 | if (isset($this->options['data'])) { |
358 | - $this->options['data'] = is_array($this->options['data']) ? http_build_query($this->options['data']) : $this->options['data'];//for better compatibility |
|
358 | + $this->options['data'] = is_array($this->options['data']) ? http_build_query($this->options['data']) : $this->options['data']; //for better compatibility |
|
359 | 359 | } |
360 | 360 | if (isset($this->withURIQuery)) { |
361 | 361 | $this->options['url'] .= strpos($this->options['url'], '?') === FALSE ? '?' : '&'; |
@@ -371,11 +371,11 @@ discard block |
||
371 | 371 | preg_match('/\/\/([^\/]+)/', $this->options['url'], $matches); |
372 | 372 | $host = $matches[1]; |
373 | 373 | if (empty($this->options['headers']) || !is_array($this->options['headers'])) { |
374 | - $this->options['headers'] = array('Host: ' . $host); |
|
374 | + $this->options['headers'] = array('Host: '.$host); |
|
375 | 375 | } else { |
376 | - $this->options['headers'][] = 'Host: ' . $host; |
|
376 | + $this->options['headers'][] = 'Host: '.$host; |
|
377 | 377 | } |
378 | - $this->options['url'] = preg_replace('/\/\/([^\/]+)/', '//' . $this->options['ip'], $this->options['url']); |
|
378 | + $this->options['url'] = preg_replace('/\/\/([^\/]+)/', '//'.$this->options['ip'], $this->options['url']); |
|
379 | 379 | unset($this->options['ip']); |
380 | 380 | unset($host); |
381 | 381 | } |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | //convert secs to milliseconds |
395 | 395 | if (defined('CURLOPT_TIMEOUT_MS')) { |
396 | 396 | if (!isset($this->options['timeout_ms'])) { |
397 | - $this->options['timeout_ms'] = intval($this->options['timeout'] * 1000); |
|
397 | + $this->options['timeout_ms'] = intval($this->options['timeout']*1000); |
|
398 | 398 | } else { |
399 | 399 | $this->options['timeout_ms'] = intval($this->options['timeout_ms']); |
400 | 400 | } |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | public function onEnd(callable $callback) |
411 | 411 | { |
412 | 412 | if (!is_callable($callback)) { |
413 | - throw new InvalidArgumentException('callback not is callable :' . print_r($callback, 1)); |
|
413 | + throw new InvalidArgumentException('callback not is callable :'.print_r($callback, 1)); |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | $this->endCallback = $callback; |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | private static function log(Response $response) |
459 | 459 | { |
460 | 460 | if ($response->hasErrors()) { |
461 | - self::$logger->error($response->request->getURI() . "\t" . $response->error, array( |
|
461 | + self::$logger->error($response->request->getURI()."\t".$response->error, array( |
|
462 | 462 | 'response' => print_r($response, 1), |
463 | 463 | )); |
464 | 464 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | 'method' => $method, |
53 | 53 | 'url' => $uri, |
54 | 54 | 'data' => $payload, |
55 | - ) + $options; |
|
55 | + )+$options; |
|
56 | 56 | $this->addOptions(array($options)); |
57 | 57 | return $this; |
58 | 58 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | public function execute() |
92 | 92 | { |
93 | 93 | // if($this->isLazy) return array(); |
94 | - $sleepTime = 1000;//microsecond, prevent CPU 100% |
|
94 | + $sleepTime = 1000; //microsecond, prevent CPU 100% |
|
95 | 95 | do { |
96 | 96 | curl_multi_exec(self::$multiHandler, $active); |
97 | 97 | // bug in PHP 5.3.18+ where curl_multi_select can return -1 |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | usleep($sleepTime); |
101 | 101 | } |
102 | 102 | usleep($sleepTime); |
103 | - } while ($active); |
|
103 | + }while ($active); |
|
104 | 104 | $return = array(); |
105 | 105 | foreach (self::$requestPool as $request) { |
106 | 106 | $response = $request->makeResponse(true); |