Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
缓存php文件并返回缓存的html文件_Php_Performance - Fatal编程技术网

缓存php文件并返回缓存的html文件

缓存php文件并返回缓存的html文件,php,performance,Php,Performance,我有一个非常大的mysql表,因此我试图更改整个php文件并返回缓存的html文件 我用过这个,效果很好,但是当编写新的html文件的时候,它需要很长时间才能加载…我需要在哪里修改它 Php代码: $cachefile = 'cache.html'; $cachetime = 4 * 60; // Serve from the cache if it is younger than $cachetime if (file_exists($cachefile) && time()

我有一个非常大的mysql表,因此我试图更改整个php文件并返回缓存的html文件

我用过这个,效果很好,但是当编写新的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
$cachefile='cache.html';
$cachetime=4*60;
//如果缓存小于$cachetime,则从缓存提供服务
如果(file_存在($cachefile)&&time()-$cachetime
假设您正在谈论HTML表,这样的缓存不会加快加载时间。
浏览器需要花费太多的时间来呈现一个大表,而不是PHP来生成它


因此,为了加快速度,您必须减小表的大小或实现某种分页或动态加载

有没有可能不用动态加载就可以完成呢?我用的不是html表。我在mysql中使用xampp数据包