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 may be the same as WordPress#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.
  • Loading branch information
TysonAndre committed Jun 14, 2017
1 parent 87932f5 commit c7d8ee4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions library/Requests/Transport/cURL.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,14 @@ public function request_multiple($requests, $options) {
}
while ($status === CURLM_CALL_MULTI_PERFORM);

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

$to_process = array();

// Read the information as needed
Expand Down

0 comments on commit c7d8ee4

Please sign in to comment.