Skip to content

Commit

Permalink
Fixes WordPress#283 : Fixes CPU busy loop when using request_multiple.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
TysonAndre committed Jun 13, 2017
1 parent 87932f5 commit 7234c79
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion library/Requests/Transport/cURL.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,20 @@ public function request_multiple($requests, $options) {

do {
$status = curl_multi_exec($multihandle, $active);
// Return immediately if there's work to be done.
if ($status !== CURLM_CALL_MULTI_PERFORM) {
break;
}
// Block until there is activity on any of the curl_multi connections.
// Timeouts can be specified in microseconds.
// Provide curl_multi_select with a timeout of 100ms (May not be necessary).
// As a fallback, if curl_multi_select couldn't properly asynchronously wait for input, sleep for 0.1 ms.
$select_status = curl_multi_select($multihandle, 0.1);
if ($select_status === -1) {
usleep(100);
}
}
while ($status === CURLM_CALL_MULTI_PERFORM);
while (true);

$to_process = array();

Expand Down

0 comments on commit 7234c79

Please sign in to comment.