← All changes
|
includes/sdk/google/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php
+21
-19
1.2.12
→
1.4.2
View file →
| @@ -1,14 +1,14 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -namespace Dudlewebs\WPMCS\GuzzleHttp\Handler; | |
| 3 | +namespace Dudlewebs\WPMCS\GCP\GuzzleHttp\Handler; | |
| 4 | 4 | |
| 5 | 5 | use Closure; |
| 6 | -use Dudlewebs\WPMCS\GuzzleHttp\Promise as P; | |
| 7 | -use Dudlewebs\WPMCS\GuzzleHttp\Promise\Promise; | |
| 8 | -use Dudlewebs\WPMCS\GuzzleHttp\Promise\PromiseInterface; | |
| 9 | -use Dudlewebs\WPMCS\GuzzleHttp\Utils; | |
| 10 | -use Dudlewebs\WPMCS\Psr\Http\Message\RequestInterface; | |
| 6 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Promise as P; | |
| 7 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Promise\Promise; | |
| 8 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Promise\PromiseInterface; | |
| 9 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Utils; | |
| 10 | +use Dudlewebs\WPMCS\GCP\Psr\Http\Message\RequestInterface; | |
| 11 | 11 | /** |
| 12 | 12 | * Returns an asynchronous response using curl_multi_* functions. |
| 13 | 13 | * |
| 14 | 14 | * When using the CurlMultiHandler, custom curl options can be specified as an |
| @@ -63,9 +63,9 @@ | ||
| 63 | 63 | $this->factory = $options['handle_factory'] ?? new CurlFactory(50); |
| 64 | 64 | if (isset($options['select_timeout'])) { |
| 65 | 65 | $this->selectTimeout = $options['select_timeout']; |
| 66 | 66 | } elseif ($selectTimeout = Utils::getenv('GUZZLE_CURL_SELECT_TIMEOUT')) { |
| 67 | - @trigger_error('Since guzzlehttp/guzzle 7.2.0: Using environment variable GUZZLE_CURL_SELECT_TIMEOUT is deprecated. Use option "select_timeout" instead.', \E_USER_DEPRECATED); | |
| 67 | + @\trigger_error('Since guzzlehttp/guzzle 7.2.0: Using environment variable GUZZLE_CURL_SELECT_TIMEOUT is deprecated. Use option "select_timeout" instead.', \E_USER_DEPRECATED); | |
| 68 | 68 | $this->selectTimeout = (int) $selectTimeout; |
| 69 | 69 | } else { |
| 70 | 70 | $this->selectTimeout = 1; |
| 71 | 71 | } |
| @@ -93,9 +93,9 @@ | ||
| 93 | 93 | } |
| 94 | 94 | $this->_mh = $multiHandle; |
| 95 | 95 | foreach ($this->options as $option => $value) { |
| 96 | 96 | // A warning is raised in case of a wrong option. |
| 97 | - curl_multi_setopt($this->_mh, $option, $value); | |
| 97 | + \curl_multi_setopt($this->_mh, $option, $value); | |
| 98 | 98 | } |
| 99 | 99 | return $this->_mh; |
| 100 | 100 | } |
| 101 | 101 | public function __destruct() |
| @@ -104,13 +104,13 @@ | ||
| 104 | 104 | \curl_multi_close($this->_mh); |
| 105 | 105 | unset($this->_mh); |
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | - public function __invoke(RequestInterface $request, array $options): PromiseInterface | |
| 108 | + public function __invoke(RequestInterface $request, array $options) : PromiseInterface | |
| 109 | 109 | { |
| 110 | 110 | $easy = $this->factory->create($request, $options); |
| 111 | 111 | $id = (int) $easy->handle; |
| 112 | - $promise = new Promise([$this, 'execute'], function () use ($id) { | |
| 112 | + $promise = new Promise([$this, 'execute'], function () use($id) { | |
| 113 | 113 | return $this->cancel($id); |
| 114 | 114 | }); |
| 115 | 115 | $this->addRequest(['easy' => $easy, 'deferred' => $promise]); |
| 116 | 116 | return $promise; |
| @@ -117,9 +117,9 @@ | ||
| 117 | 117 | } |
| 118 | 118 | /** |
| 119 | 119 | * Ticks the curl event loop. |
| 120 | 120 | */ |
| 121 | - public function tick(): void | |
| 121 | + public function tick() : void | |
| 122 | 122 | { |
| 123 | 123 | // Add any delayed handles if needed. |
| 124 | 124 | if ($this->delays) { |
| 125 | 125 | $currentTime = Utils::currentTime(); |
| @@ -147,9 +147,9 @@ | ||
| 147 | 147 | } |
| 148 | 148 | /** |
| 149 | 149 | * Runs \curl_multi_exec() inside the event loop, to prevent busy looping |
| 150 | 150 | */ |
| 151 | - private function tickInQueue(): void | |
| 151 | + private function tickInQueue() : void | |
| 152 | 152 | { |
| 153 | 153 | if (\curl_multi_exec($this->_mh, $this->active) === \CURLM_CALL_MULTI_PERFORM) { |
| 154 | 154 | \curl_multi_select($this->_mh, 0); |
| 155 | 155 | P\Utils::queue()->add(Closure::fromCallable([$this, 'tickInQueue'])); |
| @@ -157,9 +157,9 @@ | ||
| 157 | 157 | } |
| 158 | 158 | /** |
| 159 | 159 | * Runs until all outstanding connections have completed. |
| 160 | 160 | */ |
| 161 | - public function execute(): void | |
| 161 | + public function execute() : void | |
| 162 | 162 | { |
| 163 | 163 | $queue = P\Utils::queue(); |
| 164 | 164 | while ($this->handles || !$queue->isEmpty()) { |
| 165 | 165 | // If there are no transfers, then sleep for the next delay |
| @@ -168,9 +168,9 @@ | ||
| 168 | 168 | } |
| 169 | 169 | $this->tick(); |
| 170 | 170 | } |
| 171 | 171 | } |
| 172 | - private function addRequest(array $entry): void | |
| 172 | + private function addRequest(array $entry) : void | |
| 173 | 173 | { |
| 174 | 174 | $easy = $entry['easy']; |
| 175 | 175 | $id = (int) $easy->handle; |
| 176 | 176 | $this->handles[$id] = $entry; |
| @@ -186,11 +186,11 @@ | ||
| 186 | 186 | * @param int $id Handle ID to cancel and remove. |
| 187 | 187 | * |
| 188 | 188 | * @return bool True on success, false on failure. |
| 189 | 189 | */ |
| 190 | - private function cancel($id): bool | |
| 190 | + private function cancel($id) : bool | |
| 191 | 191 | { |
| 192 | - if (!is_int($id)) { | |
| 192 | + if (!\is_int($id)) { | |
| 193 | 193 | trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing an integer to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
| 194 | 194 | } |
| 195 | 195 | // Cannot cancel if it has been processed. |
| 196 | 196 | if (!isset($this->handles[$id])) { |
| @@ -198,12 +198,14 @@ | ||
| 198 | 198 | } |
| 199 | 199 | $handle = $this->handles[$id]['easy']->handle; |
| 200 | 200 | unset($this->delays[$id], $this->handles[$id]); |
| 201 | 201 | \curl_multi_remove_handle($this->_mh, $handle); |
| 202 | - \curl_close($handle); | |
| 202 | + if (\PHP_VERSION_ID < 80000) { | |
| 203 | + \curl_close($handle); | |
| 204 | + } | |
| 203 | 205 | return \true; |
| 204 | 206 | } |
| 205 | - private function processMessages(): void | |
| 207 | + private function processMessages() : void | |
| 206 | 208 | { |
| 207 | 209 | while ($done = \curl_multi_info_read($this->_mh)) { |
| 208 | 210 | if ($done['msg'] !== \CURLMSG_DONE) { |
| 209 | 211 | // if it's not done, then it would be premature to remove the handle. ref https://github.com/guzzle/guzzle/pull/2892#issuecomment-945150216 |
| @@ -220,9 +222,9 @@ | ||
| 220 | 222 | $entry['easy']->errno = $done['result']; |
| 221 | 223 | $entry['deferred']->resolve(CurlFactory::finish($this, $entry['easy'], $this->factory)); |
| 222 | 224 | } |
| 223 | 225 | } |
| 224 | - private function timeToNext(): int | |
| 226 | + private function timeToNext() : int | |
| 225 | 227 | { |
| 226 | 228 | $currentTime = Utils::currentTime(); |
| 227 | 229 | $nextTime = \PHP_INT_MAX; |
| 228 | 230 | foreach ($this->delays as $time) { |