<?php
set_time_error(0);
function readCacheFile($url, $file, $delay = 3600) {
// @author: huyphungvan@gmail.com
if(!file_exists($file)) {
// first time
$src = file_get_contents($url);
file_put_contents($file, $src);
return $src;
} else {
$now = time();
$cached_time = filemtime($file);
if ($now - $cached_time > $delay) {
// re-cache
$src = file_get_contents($url);
file_put_contents($file, $src);
return $src;
} else {
// read cached file
return file_get_contents($file);
}
}
}
$src = readCacheFile("http://phungvanhuy.net", "cache/pvh.htm");
echo $src;
?>
Title:
cache url file
Description:
<?php set_time_error(0); function readCacheFile($url, $file, $delay = 3600) { // @author: huyphungvan@gmail.com if(!file_exists($...
...
Rating:
4