@@ -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,20 +44,20 @@ 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(){ |
|
51 | - if($this->body && $this->request->getIni('header')){//has header |
|
50 | + public function parse() { |
|
51 | + if ($this->body && $this->request->getIni('header')) {//has header |
|
52 | 52 | $headers = rtrim(substr($this->body, 0, $this->info['header_size'])); |
53 | 53 | $this->body = substr($this->body, $this->info['header_size']); |
54 | 54 | $headers = explode(PHP_EOL, $headers); |
55 | 55 | array_shift($headers); // HTTP HEADER |
56 | - foreach($headers as $h) { |
|
57 | - if(false !== strpos($h, ':')) |
|
56 | + foreach ($headers as $h) { |
|
57 | + if (false !== strpos($h, ':')) |
|
58 | 58 | list($k, $v) = explode(':', $h, 2); |
59 | 59 | else |
60 | - list($k, $v) = array($h,''); |
|
60 | + list($k, $v) = array($h, ''); |
|
61 | 61 | |
62 | 62 | $this->header[trim($k)] = trim($v); |
63 | 63 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | $content_type = explode(';', $content_type); |
70 | 70 | $this->contentType = $content_type[0]; |
71 | 71 | if (count($content_type) == 2 && strpos($content_type[1], '=') !== false) { |
72 | - list( , $this->charset) = explode('=', $content_type[1]); |
|
72 | + list(, $this->charset) = explode('=', $content_type[1]); |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | class Request extends Http { |
17 | 17 | protected static $curlAlias = array( |
18 | 18 | 'url' => 'CURLOPT_URL', |
19 | - 'debug' => 'CURLOPT_VERBOSE',//for debug verbose |
|
19 | + 'debug' => 'CURLOPT_VERBOSE', //for debug verbose |
|
20 | 20 | 'method' => 'CURLOPT_CUSTOMREQUEST', |
21 | 21 | 'data' => 'CURLOPT_POSTFIELDS', // array or string , file begin with '@' |
22 | 22 | 'ua' => 'CURLOPT_USERAGENT', |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | if (null === ($rawField = constant($alias))) {throw new InvalidArgumentException('field is invalid'); |
83 | 83 | } |
84 | 84 | |
85 | - return isset($this->options[$rawField])?$this->options[$rawField]:false; |
|
85 | + return isset($this->options[$rawField]) ? $this->options[$rawField] : false; |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | |
@@ -116,10 +116,10 @@ discard block |
||
116 | 116 | } |
117 | 117 | |
118 | 118 | if (isset($this->options['data'])) { |
119 | - $this->options['data'] = is_array($this->options['data'])?http_build_query($this->options['data']):$this->options['data'];//for better compatibility |
|
119 | + $this->options['data'] = is_array($this->options['data']) ? http_build_query($this->options['data']) : $this->options['data']; //for better compatibility |
|
120 | 120 | } |
121 | 121 | if (isset($this->withURIQuery)) { |
122 | - $this->options['url'] .= strpos($this->options['url'], '?') === FALSE?'?':'&'; |
|
122 | + $this->options['url'] .= strpos($this->options['url'], '?') === FALSE ? '?' : '&'; |
|
123 | 123 | $this->options['url'] .= $this->withURIQuery; |
124 | 124 | } |
125 | 125 | if (isset($this->options['callback'])) { |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | return $alias; |
247 | 247 | } |
248 | 248 | public function makeResponse($isMultiCurl = false) { |
249 | - $body = $isMultiCurl?curl_multi_getcontent($this->curlHandle):curl_exec($this->curlHandle); |
|
249 | + $body = $isMultiCurl ? curl_multi_getcontent($this->curlHandle) : curl_exec($this->curlHandle); |
|
250 | 250 | $info = curl_getinfo($this->curlHandle); |
251 | 251 | $errno = curl_errno($this->curlHandle); |
252 | 252 | $error = curl_error($this->curlHandle); |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | * @return array(Response) |
70 | 70 | */ |
71 | 71 | public function execute() { |
72 | - $sleepTime = 1000;//microsecond, prevent CPU 100% |
|
73 | - do{ |
|
72 | + $sleepTime = 1000; //microsecond, prevent CPU 100% |
|
73 | + do { |
|
74 | 74 | curl_multi_exec(self::$multiHandler, $active); |
75 | 75 | // bug in PHP 5.3.18+ where curl_multi_select can return -1 |
76 | 76 | // https://bugs.php.net/bug.php?id=63411 |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | usleep($sleepTime); |
79 | 79 | } |
80 | 80 | usleep($sleepTime); |
81 | - }while($active); |
|
81 | + }while ($active); |
|
82 | 82 | $return = array(); |
83 | 83 | foreach (self::$requestPool as $request) { |
84 | 84 | $response = $request->makeResponse(true); |