@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | public function __construct($maxConcurrent = 10, $usleep = 100000, $userAgent = 'cvweiss/guzzler/', $curlOptions = []) |
16 | 16 | { |
17 | - $curlOptions = $curlOptions == [] ? [CURLOPT_FRESH_CONNECT => false] : $curlOptions; |
|
17 | + $curlOptions = $curlOptions == [] ? [CURLOPT_FRESH_CONNECT => false] : $curlOptions; |
|
18 | 18 | |
19 | 19 | $this->curl = new \GuzzleHttp\Handler\CurlMultiHandler(); |
20 | 20 | $this->handler = \GuzzleHttp\HandlerStack::create($this->curl); |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | $ms = microtime(); |
34 | 34 | do { |
35 | 35 | $this->curl->tick(); |
36 | - if ($this->concurrent >= $this->maxConcurrent) usleep(max(1, min(1000000, $this->usleep))); |
|
36 | + if ($this->concurrent >= $this->maxConcurrent) usleep(max(1, min(1000000, $this->usleep))); |
|
37 | 37 | } while ($this->concurrent >= $this->maxConcurrent); |
38 | 38 | return max(0, microtime() - $ms); |
39 | 39 | } |
@@ -60,14 +60,14 @@ discard block |
||
60 | 60 | $this->verifyCallable($fulfilled); |
61 | 61 | $this->verifyCallable($rejected); |
62 | 62 | |
63 | - $params['uri'] = $uri; |
|
64 | - $params['fulfilled'] = $fulfilled; |
|
65 | - $params['rejected'] = $rejected; |
|
66 | - $params['setup'] = $setup; |
|
67 | - $params['callType'] = $callType; |
|
68 | - $params['body'] = $body; |
|
63 | + $params['uri'] = $uri; |
|
64 | + $params['fulfilled'] = $fulfilled; |
|
65 | + $params['rejected'] = $rejected; |
|
66 | + $params['setup'] = $setup; |
|
67 | + $params['callType'] = $callType; |
|
68 | + $params['body'] = $body; |
|
69 | 69 | |
70 | - $redis = $this->applyEtag($setup, $params); |
|
70 | + $redis = $this->applyEtag($setup, $params); |
|
71 | 71 | |
72 | 72 | $guzzler = $this; |
73 | 73 | $request = new \GuzzleHttp\Psr7\Request($callType, $uri, $setup, $body); |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | $guzzler->dec(); |
77 | 77 | $content = (string) $response->getBody(); |
78 | 78 | $this->lastHeaders = array_change_key_case($response->getHeaders()); |
79 | - $this->applyEtagPost($this->lastHeaders, $params['uri'], $content, $redis); |
|
79 | + $this->applyEtagPost($this->lastHeaders, $params['uri'], $content, $redis); |
|
80 | 80 | $fulfilled($guzzler, $params, $content); |
81 | 81 | }, |
82 | 82 | function($connectionException) use (&$guzzler, &$rejected, &$params) { |
@@ -98,14 +98,14 @@ discard block |
||
98 | 98 | if ($etag != "") $setup['If-None-Match'] = $etag; |
99 | 99 | } |
100 | 100 | unset($setup['etag']); |
101 | - return $redis; |
|
101 | + return $redis; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | protected function applyEtagPost($headers, $uri, $content, $redis) |
105 | 105 | { |
106 | 106 | if (isset($headers['etag']) && strlen($content) == 0 && $redis !== null) { |
107 | - $redis->setex("guzzler:etags:$uri", 604800, $headers['etag'][0]); |
|
108 | - } |
|
107 | + $redis->setex("guzzler:etags:$uri", 604800, $headers['etag'][0]); |
|
108 | + } |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | public function verifyCallable($callable) |
@@ -33,7 +33,9 @@ discard block |
||
33 | 33 | $ms = microtime(); |
34 | 34 | do { |
35 | 35 | $this->curl->tick(); |
36 | - if ($this->concurrent >= $this->maxConcurrent) usleep(max(1, min(1000000, $this->usleep))); |
|
36 | + if ($this->concurrent >= $this->maxConcurrent) { |
|
37 | + usleep(max(1, min(1000000, $this->usleep))); |
|
38 | + } |
|
37 | 39 | } while ($this->concurrent >= $this->maxConcurrent); |
38 | 40 | return max(0, microtime() - $ms); |
39 | 41 | } |
@@ -95,7 +97,9 @@ discard block |
||
95 | 97 | $redis = isset($setup['etag']) ? $setup['etag'] : null; |
96 | 98 | if ($redis !== null && $params['callType'] == 'GET') { |
97 | 99 | $etag = $redis->get("guzzler:etags:" . $params['uri']); |
98 | - if ($etag != "") $setup['If-None-Match'] = $etag; |
|
100 | + if ($etag != "") { |
|
101 | + $setup['If-None-Match'] = $etag; |
|
102 | + } |
|
99 | 103 | } |
100 | 104 | unset($setup['etag']); |
101 | 105 | return $redis; |