diff options
author | Christian Helbling | 2015-11-16 15:20:03 +0100 |
---|---|---|
committer | Christian Helbling | 2015-11-16 15:20:03 +0100 |
commit | 2587921cdf5f9139c6f2483dddb12df27740fef5 (patch) | |
tree | b67941b93eda2490800efafd1f5410bdd754bf16 /it_url.class | |
parent | babb09e211e93c6236bc19e60a4f649e573a6f4e (diff) | |
parent | 3b4aeabd9186666e025d3233f06f7458356bfc37 (diff) | |
download | itools-2587921cdf5f9139c6f2483dddb12df27740fef5.tar.gz itools-2587921cdf5f9139c6f2483dddb12df27740fef5.tar.bz2 itools-2587921cdf5f9139c6f2483dddb12df27740fef5.zip |
Merge branch 'master' into cs/php7
Diffstat (limited to 'it_url.class')
-rw-r--r-- | it_url.class | 16 |
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; } |