From f6161a1670a419d14f4000863cabeaa26ee1638a Mon Sep 17 00:00:00 2001
From: Nathan Gass
Date: Mon, 3 Dec 2012 14:56:03 +0000
Subject: curl_multi_select can return -1 without select when polling is
 necessary (see curl_multi_fdset doku)

---
 it_url.class | 37 ++++++++++++++++++-------------------
 1 file changed, 18 insertions(+), 19 deletions(-)

diff --git a/it_url.class b/it_url.class
index d8e5afb..81729c6 100644
--- a/it_url.class
+++ b/it_url.class
@@ -404,29 +404,28 @@ function get_multi($p=null)
 	} while ($mrc == CURLM_CALL_MULTI_PERFORM);
 
 	$timeout = 0.001;	# Very short timeout to work around problem with first select call on cURL 7.25.0
-	while (!$abort && $active && $mrc == CURLM_OK) 
+	while (!$abort && $active && $mrc == CURLM_OK)
 	{
-		if (curl_multi_select($mh, $timeout) != -1) 
-		{
-			do {
-				$mrc = curl_multi_exec($mh, $active);
+		if (curl_multi_select($mh, $timeout) == -1)
+			usleep($timeout * 1000000);
+		do {
+			$mrc = curl_multi_exec($mh, $active);
 
-				while (($info = curl_multi_info_read($mh)) !== false)
+			while (($info = curl_multi_info_read($mh)) !== false)
+			{
+				if ($info['msg'] == CURLMSG_DONE)
 				{
-					if ($info['msg'] == CURLMSG_DONE)
-					{
-						$key = $keys[$info['handle']];
-						EDC('reqtimings', $key, $info['result'], (microtime(true) - $start) * 1000);
-						if ($info['result'] == CURLE_OK)
-							$results_unordered[$key] = curl_multi_getcontent($info['handle']);
-						else
-							$results_unordered[$key] = false;
-						if (($handler = $urls[$keys[$info['handle']]]['handler']))
-							$abort = $handler($info['result'], $results_unordered[$key]);
-					}
+					$key = $keys[$info['handle']];
+					EDC('reqtimings', $key, $info['result'], (microtime(true) - $start) * 1000);
+					if ($info['result'] == CURLE_OK)
+						$results_unordered[$key] = curl_multi_getcontent($info['handle']);
+					else
+						$results_unordered[$key] = false;
+					if (($handler = $urls[$keys[$info['handle']]]['handler']))
+						$abort = $handler($info['result'], $results_unordered[$key]);
 				}
-			} while ($mrc == CURLM_CALL_MULTI_PERFORM);
-		}
+			}
+		} while ($mrc == CURLM_CALL_MULTI_PERFORM);
 		$timeout = 0.1;	# Longer delay to avoid busy loop but shorter than default of 1s in case we stil hit cURL 7.25.0 problem
 	}
 
-- 
cgit v1.2.3