-1

非常に大きなmysqlテーブルがあるため、phpファイル全体をキャッシュして、キャッシュされたhtmlファイルを返そうとしています。

私はこのキャッシュ動的PHPページを簡単に使用しましたが、うまく機能しますが、新しい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
4

1 に答える 1

0

HTML テーブルについて話していると仮定すると、そのようなキャッシュは読み込み時間を短縮しません。
大きなテーブルを生成するのに PHP ではなく、ブラウザがレンダリングするのに時間がかかりすぎます。

したがって、処理を高速化するには、テーブル サイズを縮小するか、何らかのページネーションや動的読み込みを実装する必要があります。

于 2013-01-19T13:14:35.370 に答える