我一直在使用一個基本的緩存系統在我的網站基於this link自動創建PHP
它迄今行之有效的寄託都我想要做的緩存文件。
$cachefile = 'cache/'. basename($_SERVER['QUERY_STRING']) . '.html';
$cachetime = 1440 * 60;
if (file_exists($cachefile) && (time() - $cachetime < filemtime($cachefile))) {
include($cachefile);
echo "<!-- Cached ".date('jS F Y H:i', filemtime($cachefile))." -->";
exit;
}
ob_start();
// My html/php code here
$fp = fopen($cachefile, 'w'); // open the cache file for writing
fwrite($fp, ob_get_contents()); // save the contents of output buffer to the file
fclose($fp); // close
ob_end_flush(); // Send to browser
不過,我有一對夫婦的更詳細的MySQL的查詢網頁,我已經花了很多時間公平位優化它但是它仍然需要大約10秒的時候我查詢它在MySQL,甚至更長的運行網站。有時候,當我收到下面的消息時,它似乎會超時。
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the requestGET http://www.example.com
Reason: Error reading from remote server
這是不是一個巨大的問題,因爲,因爲我只用了第一人稱上面的緩存系統,點擊它一天獲得的延遲和休息的時間得到了用戶的緩存頁面,以便對他們來說實際上是相當快的。
我想讓自己不必每天都要成爲第一個訪問頁面並自動執行此過程的人,因此每天17:00(在服務器上)文件被寫入緩存。
我該如何做到最好?
如果你有linux服務器 - cron作業 – vodich