From c7d8ee49fcf50ed314d13312839922379f1f173b Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Tue, 13 Jun 2017 08:39:30 -0700 Subject: [PATCH] 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. --- library/Requests/Transport/cURL.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/library/Requests/Transport/cURL.php b/library/Requests/Transport/cURL.php index 4429edb64..9de5703df 100644 --- a/library/Requests/Transport/cURL.php +++ b/library/Requests/Transport/cURL.php @@ -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