From 4b473ef5045dc6883dd3fda1543a3ce2e2ba77fa Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Wed, 27 Jan 2010 13:56:48 +0000 Subject: do one retry by default --- it_url.class | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/it_url.class b/it_url.class index af6e9af..b4af739 100644 --- a/it_url.class +++ b/it_url.class @@ -227,6 +227,7 @@ function is_reachable($timeout = 5) * @param $p['totaltimeout']: timeout for the whole function call * @param $p['filemtime']: Add HTTP header to only fetch when newer than this, otherwise return true instead of data * @param $p['data']: POST data array with key-value pairs + * @param $p['retries']: Number of retries if download fails, default 1 * @return contents of resulting page, considering redirects, excluding headers, or false on error */ function get($p=null, $timeout=5) @@ -234,7 +235,7 @@ function get($p=null, $timeout=5) if (!is_array($p)) $p = array('url' => $p, 'timeout' => $timeout); - $p += array('totaltimeout' => "999999", 'timeout' => 5); + $p += array('totaltimeout' => "999999", 'timeout' => 5, 'retries' => 1); if ($p['url']) $url = new it_url($p['url']); @@ -329,7 +330,13 @@ function get($p=null, $timeout=5) } } - return time() < $endtime ? $result : false; + if (time() >= $endtime) + $result = false; + + if (!$result && $p['retries'] > 0 && $url->result < 400) + $result = $url->get(array('retries' => $p['retries'] - 1) + $p); + + return $result; } -- cgit v1.2.3