summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--it_url.class11
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;
}