我使用的是PHP Simple HTML DOM Parser和$HTML->load_file
include('simple_html_dom.php');
$html = new simple_html_dom();
$html->load_file('https://www.google.com/finance?q=goog');
下面的链接演示了一种强制缓存内容的方法。我需要检索内容根据url的最后部分而变化的页面。是否可以修改下面的代码以强制缓存,例如,如果我检索以下页面:
google.com/finance?q=粘稠
google.com/finance?q=wwwfx
google.com/finance?q=vigrx
我可以缓存这些页面中的每一个直到会话结束,因为我将重复需要页面内容。
缓存PHP简单HTML DOM解析器
function cache_get_contents($url, $offset = 600, $override = false) {
$file = '/tmp/file_cache_' . md5($url);
if (!$override && file_exists($file) && filemtime($file) > time() - $offset)
return file_get_contents($file);
$contents = file_get_contents($url);
if ($contents === false)
return false;
file_put_contents($file, $contents);
return $contents;
}
Carter为您指明了正确的方向,您可能会发现以下信息很有帮助。
http://en.wikipedia.org/wiki/List_of_PHP_accelerators
https://www.addedbytes.com/articles/for-beginners/output-caching-for-beginners/
http://www.phpfastcache.com/
http://www.wpulti.org/best-php-cache-scripts-classes/
http://codecanyon.net/item/php-simple-cache/4169137?ref=globalcube&ref=全局多维数据集&clickthrough_id=384995784&redirect_back=真实