summaryrefslogtreecommitdiff
path: root/it_url.class
diff options
context:
space:
mode:
Diffstat (limited to 'it_url.class')
-rw-r--r--it_url.class16
1 files changed, 13 insertions, 3 deletions
diff --git a/it_url.class b/it_url.class
index 2204b60..fb5a1ff 100644
--- a/it_url.class
+++ b/it_url.class
@@ -156,6 +156,7 @@ function is_reachable($timeout = 5)
* @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
+ * @param $p['retrysleep'] Number of seconds to wait before retry, fractions ok
* @return contents of resulting page, considering redirects, excluding headers, or false on error
*/
function get($p=null, $timeout=5)
@@ -190,7 +191,10 @@ function get($p=null, $timeout=5)
}
if (!$result && $p['retries'] > 0 && $url->result < 400)
+ {
+ usleep($p['retrysleep']*1000000);
$result = $url->get(array('retries' => $p['retries'] - 1) + $p);
+ }
if (($filter = EDC('res')) && strstr($p['url'], it::replace(array('1' => ":"), $filter)))
ED($result);
@@ -623,9 +627,12 @@ function get_cache($p = array())
if (!($result = @filesize($dstpath) && @rename($dstpath, $path)))
{
@unlink($dstpath);
- @unlink($path);
+ if (!$p['keepfailed'])
+ @unlink($path);
+ $result = file_exists($path);
}
+ $cachemiss = 1;
it_url::_unlock($path, $lock);
}
else
@@ -645,7 +652,10 @@ function get_cache($p = array())
exec("nohup bash -c 'cd {$p['cachedir']} && sleep 10 && find ?? -mmin +$maxagemin -print0 | xargs -0 -r rm' </dev/null >/dev/null 2>&1 &");
}
- EDC('getcache', $result, $path);
+ if (EDC('getcachelog'))
+ it::log('debug', 'getcachelog', "miss=" . intval($cachemiss), $p['url']);
+
+ ### EDC('getcache', $result, $path); # too verbose
return $result ? ($p['returnheaders'] ? array($path, $headers) : $path) : false;
}
@@ -669,7 +679,7 @@ function _expired($path, $maxage)
if ($result = EDC('nocache') ? false : @filemtime($path))
{
if (time() - $result > $maxage)
- EDC('getcache', "expired", $path);
+ EDC('getcache', "expired", $maxage, $path);
else
$result = false;
}