From 3f4ca320fed8ae3db28b74773748c9b3035b38a6 Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Tue, 14 Aug 2012 14:59:54 +0000 Subject: Handle errors (e.g. timeouts) in it_url::get_multi by returning false for those urls --- it_url.class | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/it_url.class b/it_url.class index 305bde9..2527d7a 100644 --- a/it_url.class +++ b/it_url.class @@ -358,8 +358,8 @@ function get($p=null, $timeout=5) * @param $p['timeout']: timeout per read in seconds, defaults to 5. (TODO: fractions allowed?) * @param $p['totaltimeout']: timeout for the whole function call * @param $p['headers']: optional array of HTTP headers to send - * @return array of contents of resulting page using same keys as the urls input array, - * considering redirects, excluding headers + * @return array of contents (or false for errors like timesou) of resulting page using same + * keys as the urls input array, considering redirects, excluding headers */ function get_multi($p=null) { @@ -401,6 +401,10 @@ function get_multi($p=null) { do { $mrc = curl_multi_exec($mh, $active); + + while (($info = curl_multi_info_read($mh)) !== false) + if ($info['msg'] == CURLMSG_DONE && $info['result'] != CURLE_OK) + $error[$info['handle']] = $info['result']; } while ($mrc == CURLM_CALL_MULTI_PERFORM); } } @@ -408,7 +412,7 @@ function get_multi($p=null) $results = array(); foreach ($p['urls'] as $key => $url) { - $results[$key] = curl_multi_getcontent($ch[$key]); + $results[$key] = $error[$ch[$key]] ? false : curl_multi_getcontent($ch[$key]); curl_multi_remove_handle($mh, $ch[$key]); curl_close($ch[$key]); } -- cgit v1.2.3