Simplify MultiCurl execution loop (#1017)

* Clean up

* Simplify MultiCurl execution loop

- Removes legacy workarounds
- Deprecates MultiCurl::setRequestTimeAccuracy()
- Removes use of CURLM_CALL_MULTI_PERFORM ("As of cURL 7.20.0, this constant is not used")
This commit is contained in:
Zach Borboa
2025-11-20 23:39:03 -05:00
committed by GitHub
parent 064e78f89a
commit 4b36f455dd
3 changed files with 5 additions and 55 deletions
+3 -36
View File
@@ -19,7 +19,6 @@ class MultiCurl extends BaseCurl
private $currentRequestCount = 0;
private $concurrency = 25;
private $nextCurlId = 0;
private $preferRequestTimeAccuracy = false;
private $rateLimit = null;
private $rateLimitEnabled = false;
@@ -678,40 +677,7 @@ class MultiCurl extends BaseCurl
$this->waitUntilRequestQuotaAvailable();
}
if ($this->preferRequestTimeAccuracy) {
// Wait for activity on any curl_multi connection when curl_multi_select (libcurl) fails to correctly
// block.
// https://bugs.php.net/bug.php?id=63411
//
// Also, use a shorter curl_multi_select() timeout instead the default of one second. This allows
// pending requests to have more accurate start times. Without a shorter timeout, it can be nearly a
// full second before available request quota is rechecked and pending requests can be initialized.
if (curl_multi_select($this->multiCurl, 0.2) === -1) {
usleep(100_000);
}
curl_multi_exec($this->multiCurl, $active);
} else {
// Use multiple loops to get data off of the multi handler. Without this, the following error may appear
// intermittently on certain versions of PHP:
// curl_multi_exec(): supplied resource is not a valid cURL handle resource
// Clear out the curl buffer.
do {
$status = curl_multi_exec($this->multiCurl, $active);
} while ($status === CURLM_CALL_MULTI_PERFORM);
// Wait for more information and then get that information.
while ($active && $status === CURLM_OK) {
// Check if the network socket has some data.
if (curl_multi_select($this->multiCurl) !== -1) {
// Process the data for as long as the system tells us to keep getting it.
do {
$status = curl_multi_exec($this->multiCurl, $active);
} while ($status === CURLM_CALL_MULTI_PERFORM);
}
}
}
curl_multi_exec($this->multiCurl, $active);
while (
(is_resource($this->multiCurl) || $this->multiCurl instanceof \CurlMultiHandle) &&
@@ -801,10 +767,11 @@ class MultiCurl extends BaseCurl
/**
* Set request time accuracy
*
* @deprecated This method is deprecated and no longer has any effect.
*/
public function setRequestTimeAccuracy()
{
$this->preferRequestTimeAccuracy = true;
}
/**