diff options
author | Urban Müller | 2010-01-27 13:56:48 +0000 |
---|---|---|
committer | Urban Müller | 2010-01-27 13:56:48 +0000 |
commit | 4b473ef5045dc6883dd3fda1543a3ce2e2ba77fa (patch) | |
tree | 73f2aae46b23fa76280ab0d43c3a7993ac9260bb | |
parent | 51f8681507305e535203f861ce1a9243b14d7488 (diff) | |
download | itools-4b473ef5045dc6883dd3fda1543a3ce2e2ba77fa.tar.gz itools-4b473ef5045dc6883dd3fda1543a3ce2e2ba77fa.tar.bz2 itools-4b473ef5045dc6883dd3fda1543a3ce2e2ba77fa.zip |
do one retry by default
-rw-r--r-- | it_url.class | 11 |
1 files 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; } |