2013-01-19 96 views
-1

我有一個非常大的mysql表,因此我試圖chache整個php文件並返回緩存的html文件。緩存php文件並返回緩存的html文件

我用這一個Caching Dynamic PHP pages easily,它的偉大工程,但是當時間已經到來寫入新的HTML文件,它需要很長的時間來加載...我在哪裏需要修改它...

PHP代碼:

$cachefile = 'cache.html'; 
$cachetime = 4 * 60; 
// Serve from the cache if it is younger than $cachetime 
if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) { 
include($cachefile); 
echo "<!-- Cached copy, generated ".date('H:i', filemtime($cachefile))." -->\n"; 
exit; 
} 
ob_start(); // Start the output buffer 

/* Heres where you put your page content */ 

// Cache the contents to a file 
$cached = fopen($cacheFile, 'w'); 
fwrite($cached, ob_get_contents()); 
fclose($cached); 
ob_end_flush(); // Send the output to the browser 

回答

0

假設你正在談論HTML表,這樣緩存不會加快加載時間。
它需要瀏覽器花費太多時間來渲染大型表格,而不是PHP來生成它。

因此,爲了讓事情更快,您必須減少表格大小或實施某種分頁或動態加載。

+0

是否可以在沒有動態加載的情況下進行。 –

+0

我使用的不是一個html表格。我使用mysql的xampp數據包 –