@@ -150,7 +150,7 @@ public function __construct(CurlClientState $multi, $ch, array $options = null,
150
150
// Schedule the request in a non-blocking way
151
151
$ multi ->lastTimeout = null ;
152
152
$ multi ->openHandles [$ id ] = [$ ch , $ options ];
153
- curl_multi_add_handle ($ multi ->handles [ 0 ] , $ ch );
153
+ curl_multi_add_handle ($ multi ->handle , $ ch );
154
154
155
155
$ this ->canary = new Canary (static function () use ($ ch , $ multi , $ id ) {
156
156
unset($ multi ->openHandles [$ id ], $ multi ->handlesActivity [$ id ]);
@@ -160,9 +160,7 @@ public function __construct(CurlClientState $multi, $ch, array $options = null,
160
160
return ;
161
161
}
162
162
163
- foreach ($ multi ->handles as $ mh ) {
164
- curl_multi_remove_handle ($ mh , $ ch );
165
- }
163
+ curl_multi_remove_handle ($ multi ->handle , $ ch );
166
164
curl_setopt_array ($ ch , [
167
165
\CURLOPT_NOPROGRESS => true ,
168
166
\CURLOPT_PROGRESSFUNCTION => null ,
@@ -244,7 +242,7 @@ public function __destruct()
244
242
*/
245
243
private static function schedule (self $ response , array &$ runningResponses ): void
246
244
{
247
- if (isset ($ runningResponses [$ i = (int ) $ response ->multi ->handles [ 0 ] ])) {
245
+ if (isset ($ runningResponses [$ i = (int ) $ response ->multi ->handle ])) {
248
246
$ runningResponses [$ i ][1 ][$ response ->id ] = $ response ;
249
247
} else {
250
248
$ runningResponses [$ i ] = [$ response ->multi , [$ response ->id => $ response ]];
@@ -276,47 +274,39 @@ private static function perform(ClientState $multi, array &$responses = null): v
276
274
277
275
try {
278
276
self ::$ performing = true ;
277
+ $ active = 0 ;
278
+ while (\CURLM_CALL_MULTI_PERFORM === ($ err = curl_multi_exec ($ multi ->handle , $ active ))) {
279
+ }
279
280
280
- foreach ($ multi ->handles as $ i => $ mh ) {
281
- $ active = 0 ;
282
- while (\CURLM_CALL_MULTI_PERFORM === ($ err = curl_multi_exec ($ mh , $ active ))) {
283
- }
281
+ if (\CURLM_OK !== $ err ) {
282
+ throw new TransportException (curl_multi_strerror ($ err ));
283
+ }
284
284
285
- if (\CURLM_OK !== $ err ) {
286
- throw new TransportException (curl_multi_strerror ($ err ));
285
+ while ($ info = curl_multi_info_read ($ multi ->handle )) {
F440
div>
286
+ if (\CURLMSG_DONE !== $ info ['msg ' ]) {
287
+ continue ;
287
288
}
289
+ $ result = $ info ['result ' ];
290
+ $ id = (int ) $ ch = $ info ['handle ' ];
291
+ $ waitFor = @curl_getinfo ($ ch , \CURLINFO_PRIVATE ) ?: '_0 ' ;
288
292
289
- while ($ info = curl_multi_info_read ($ mh )) {
290
- if (\CURLMSG_DONE !== $ info ['msg ' ]) {
291
- continue ;
292
- }
293
- $ result = $ info ['result ' ];
294
- $ id = (int ) $ ch = $ info ['handle ' ];
295
- $ waitFor = @curl_getinfo ($ ch , \CURLINFO_PRIVATE ) ?: '_0 ' ;
296
-
297
- if (\in_array ($ result , [\CURLE_SEND_ERROR , \CURLE_RECV_ERROR , /*CURLE_HTTP2*/ 16 , /*CURLE_HTTP2_STREAM*/ 92 ], true ) && $ waitFor [1 ] && 'C ' !== $ waitFor [0 ]) {
298
- curl_multi_remove_handle ($ mh , $ ch );
299
- $ waitFor [1 ] = (string ) ((int ) $ waitFor [1 ] - 1 ); // decrement the retry counter
300
- curl_setopt ($ ch , \CURLOPT_PRIVATE , $ waitFor );
301
- curl_setopt ($ ch , \CURLOPT_FORBID_REUSE , true );
302
-
303
- if (0 === curl_multi_add_handle ($ mh , $ ch )) {
304
- continue ;
305
- }
306
- }
293
+ if (\in_array ($ result , [\CURLE_SEND_ERROR , \CURLE_RECV_ERROR , /*CURLE_HTTP2*/ 16 , /*CURLE_HTTP2_STREAM*/ 92 ], true ) && $ waitFor [1 ] && 'C ' !== $ waitFor [0 ]) {
294
+ curl_multi_remove_handle ($ multi ->handle , $ ch );
295
+ $ waitFor [1 ] = (string ) ((int ) $ waitFor [1 ] - 1 ); // decrement the retry counter
296
+ curl_setopt ($ ch , \CURLOPT_PRIVATE , $ waitFor );
297
+ curl_setopt ($ ch , \CURLOPT_FORBID_REUSE , true );
307
298
308
- if (\ CURLE_RECV_ERROR === $ result && ' H ' === $ waitFor [ 0 ] && 400 <= ( $ responses [( int ) $ ch ]-> info [ ' http_code ' ] ?? 0 )) {
309
- $ multi -> handlesActivity [ $ id ][] = new FirstChunk () ;
299
+ if (0 === curl_multi_add_handle ( $ multi -> handle , $ ch )) {
300
+ continue ;
310
301
}
311
-
312
- $ multi ->handlesActivity [$ id ][] = null ;
313
- $ multi ->handlesActivity [$ id ][] = \in_array ($ result , [\CURLE_OK , \CURLE_TOO_MANY_REDIRECTS ], true ) || '_0 ' === $ waitFor || curl_getinfo ($ ch , \CURLINFO_SIZE_DOWNLOAD ) === curl_getinfo ($ ch , \CURLINFO_CONTENT_LENGTH_DOWNLOAD ) ? null : new TransportException (sprintf ('%s for "%s". ' , curl_strerror ($ result ), curl_getinfo ($ ch , \CURLINFO_EFFECTIVE_URL )));
314
302
}
315
303
316
- if (!$ active && 0 < $ i ) {
317
- curl_multi_close ($ mh );
318
- unset($ multi ->handles [$ i ]);
304
+ if (\CURLE_RECV_ERROR === $ result && 'H ' === $ waitFor [0 ] && 400 <= ($ responses [(int ) $ ch ]->info ['http_code ' ] ?? 0 )) {
305
+ $ multi ->handlesActivity [$ id ][] = new FirstChunk ();
319
306
}
307
+
308
+ $ multi ->handlesActivity [$ id ][] = null ;
309
+ $ multi ->handlesActivity [$ id ][] = \in_array ($ result , [\CURLE_OK , \CURLE_TOO_MANY_REDIRECTS ], true ) || '_0 ' === $ waitFor || curl_getinfo ($ ch , \CURLINFO_SIZE_DOWNLOAD ) === curl_getinfo ($ ch , \CURLINFO_CONTENT_LENGTH_DOWNLOAD ) ? null : new TransportException (sprintf ('%s for "%s". ' , curl_strerror ($ result ), curl_getinfo ($ ch , \CURLINFO_EFFECTIVE_URL )));
320
310
}
321
311
} finally {
322
312
self ::$ performing = false ;
@@ -335,7 +325,7 @@ private static function select(ClientState $multi, float $timeout): int
335
325
$ timeout = min ($ timeout , 0.01 );
336
326
}
337
327
338
- return curl_multi_select ($ multi ->handles [ array_key_last ( $ multi -> handles )] , $ timeout );
328
+ return curl_multi_select ($ multi ->handle , $ timeout );
339
329
}
340
330
341
331
/**
0 commit comments