| @@ -14,8 +14,10 @@ | ||
| 14 | 14 | * When using the CurlMultiHandler, custom curl options can be specified as an |
| 15 | 15 | * associative array of curl option constants mapping to values in the |
| 16 | 16 | * **curl** key of the provided request options. |
| 17 | 17 | * |
| 18 | + * @property resource|\CurlMultiHandle $_mh Internal use only. Lazy loaded multi-handle. | |
| 19 | + * | |
| 18 | 20 | * @final |
| 19 | 21 | */ |
| 20 | 22 | class CurlMultiHandler |
| 21 | 23 | { |
| @@ -29,11 +31,11 @@ | ||
| 29 | 31 | */ |
| 30 | 32 | private $selectTimeout; |
| 31 | 33 | |
| 32 | 34 | /** |
| 33 | - * @var int Will be higher than 0 when `curl_multi_exec` is still running. | |
| 35 | + * @var resource|\CurlMultiHandle|null the currently executing resource in `curl_multi_exec`. | |
| 34 | 36 | */ |
| 35 | - private $active = 0; | |
| 37 | + private $active; | |
| 36 | 38 | |
| 37 | 39 | /** |
| 38 | 40 | * @var array Request entry handles, indexed by handle id in `addRequest`. |
| 39 | 41 | * |
| @@ -52,11 +54,8 @@ | ||
| 52 | 54 | * @var array<mixed> An associative array of CURLMOPT_* options and corresponding values for curl_multi_setopt() |
| 53 | 55 | */ |
| 54 | 56 | private $options = []; |
| 55 | 57 | |
| 56 | - /** @var resource|\CurlMultiHandle */ | |
| 57 | - private $_mh; | |
| 58 | - | |
| 59 | 58 | /** |
| 60 | 59 | * This handler accepts the following options: |
| 61 | 60 | * |
| 62 | 61 | * - handle_factory: An optional factory used to create curl handles |
| @@ -78,12 +77,8 @@ | ||
| 78 | 77 | $this->selectTimeout = 1; |
| 79 | 78 | } |
| 80 | 79 | |
| 81 | 80 | $this->options = $options['options'] ?? []; |
| 82 | - | |
| 83 | - // unsetting the property forces the first access to go through | |
| 84 | - // __get(). | |
| 85 | - unset($this->_mh); | |
| 86 | 81 | } |
| 87 | 82 | |
| 88 | 83 | /** |
| 89 | 84 | * @param string $name |
| @@ -167,10 +162,9 @@ | ||
| 167 | 162 | // See: https://bugs.php.net/bug.php?id=61141 |
| 168 | 163 | \usleep(250); |
| 169 | 164 | } |
| 170 | 165 | |
| 171 | - while (\curl_multi_exec($this->_mh, $this->active) === \CURLM_CALL_MULTI_PERFORM) { | |
| 172 | - } | |
| 166 | + while (\curl_multi_exec($this->_mh, $this->active) === \CURLM_CALL_MULTI_PERFORM); | |
| 173 | 167 | |
| 174 | 168 | $this->processMessages(); |
| 175 | 169 | } |
| 176 | 170 | |