Skip to content

Commit 7234c79

Browse files
committed
Fixes #283 : Fixes CPU busy loop when using request_multiple.
This will require more testing across various libcurl versions. I doubt that the timeout is necessary for curl_multi_select (calls select() if it can), but leaving in one just in case of bugs, so that it will end. - Haven't thoroughly checked for relevant libcurl bugs. Asynchronously wait for events with a short timeout if CURLM_CALL_MULTI_PERFORM
1 parent 87932f5 commit 7234c79

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

library/Requests/Transport/cURL.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,20 @@ public function request_multiple($requests, $options) {
219219

220220
do {
221221
$status = curl_multi_exec($multihandle, $active);
222+
// Return immediately if there's work to be done.
223+
if ($status !== CURLM_CALL_MULTI_PERFORM) {
224+
break;
225+
}
226+
// Block until there is activity on any of the curl_multi connections.
227+
// Timeouts can be specified in microseconds.
228+
// Provide curl_multi_select with a timeout of 100ms (May not be necessary).
229+
// As a fallback, if curl_multi_select couldn't properly asynchronously wait for input, sleep for 0.1 ms.
230+
$select_status = curl_multi_select($multihandle, 0.1);
231+
if ($select_status === -1) {
232+
usleep(100);
233+
}
222234
}
223-
while ($status === CURLM_CALL_MULTI_PERFORM);
235+
while (true);
224236

225237
$to_process = array();
226238

0 commit comments

Comments
 (0)