Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c7d8ee4

Browse files
committedJun 14, 2017
Fixes #283 : Fixes CPU busy loop when using request_multiple.
This may be the same as #110 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 fails.
1 parent 87932f5 commit c7d8ee4

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed
 

‎library/Requests/Transport/cURL.php

+8
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,14 @@ public function request_multiple($requests, $options) {
222222
}
223223
while ($status === CURLM_CALL_MULTI_PERFORM);
224224

225+
// Insert a select() with a maximum of a 50ms sleep here so that we don't busy loop and chew cpu
226+
$select_res = curl_multi_select($multihandle, 0.05);
227+
if ($select_res === -1) {
228+
// We were unable to select() - Sleep for 1 millisecond.
229+
// > On failure, curl_multi_select will return -1 on a select failure (from the underlying select system call).
230+
usleep(1000);
231+
}
232+
225233
$to_process = array();
226234

227235
// Read the information as needed

0 commit comments

Comments
 (0)
Please sign in to comment.