従来のキャッシング

今日、私は長い間計画していたこと、つまりサイトにスクリプトのキャッシュを配置することを決めました。 すべてのスクリプトはユーザーに送信される前に単一のファイルに収集され、GZIPで圧縮されます。すべてがスマートに見えますが、問題があります...ブラウザはこの出力スクリプトをキャッシュしたくありませんでした。



PHPは、 session_start()関数を使用するときにキャッシュ禁止ヘッダーを設定することが実験的に確立されています。



特定のファイルのキャッシュを実装するコードの例を次に示します(余分なヘッダーを削除する3つのヘッダー()関数に注意してください)。



session_start(); // - function cmsCache_control($file, $time) { $etag = md5_file($file); $expr = 60 * 60 * 24 * 7; header( "ETAG: " . $etag); header( "LAST-MODIFIED: " . gmdate( "D, d MYH:i:s" , $time) . " GMT" ); header( "CACHE-CONTROL: " ); header( "PRAGMA: " ); header( "EXPIRES: " ); if (isset($_SERVER[ "HTTP_IF_MODIFIED_SINCE" ])) { $if_modified_since = preg_replace( "/;.*$/" , "" , $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ]); if (trim($_SERVER[ "HTTP_IF_NONE_MATCH" ]) == $etag && $if_modified_since == gmdate( "D, d MYH:i:s" , $time). " GMT" ) { header( "HTTP/1.0 304 Not modified" ); header( "CACHE-CONTROL: MAX-AGE={$expr}, MUST-REVALIDATE" ); exit; } } } … cmsCache_control($_SERVER[SCRIPT_FILENAME], filemtime($_SERVER[SCRIPT_FILENAME])); // , * This source code was highlighted with Source Code Highlighter .



  1. session_start(); // - function cmsCache_control($file, $time) { $etag = md5_file($file); $expr = 60 * 60 * 24 * 7; header( "ETAG: " . $etag); header( "LAST-MODIFIED: " . gmdate( "D, d MYH:i:s" , $time) . " GMT" ); header( "CACHE-CONTROL: " ); header( "PRAGMA: " ); header( "EXPIRES: " ); if (isset($_SERVER[ "HTTP_IF_MODIFIED_SINCE" ])) { $if_modified_since = preg_replace( "/;.*$/" , "" , $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ]); if (trim($_SERVER[ "HTTP_IF_NONE_MATCH" ]) == $etag && $if_modified_since == gmdate( "D, d MYH:i:s" , $time). " GMT" ) { header( "HTTP/1.0 304 Not modified" ); header( "CACHE-CONTROL: MAX-AGE={$expr}, MUST-REVALIDATE" ); exit; } } } … cmsCache_control($_SERVER[SCRIPT_FILENAME], filemtime($_SERVER[SCRIPT_FILENAME])); // , * This source code was highlighted with Source Code Highlighter .



  2. session_start(); // - function cmsCache_control($file, $time) { $etag = md5_file($file); $expr = 60 * 60 * 24 * 7; header( "ETAG: " . $etag); header( "LAST-MODIFIED: " . gmdate( "D, d MYH:i:s" , $time) . " GMT" ); header( "CACHE-CONTROL: " ); header( "PRAGMA: " ); header( "EXPIRES: " ); if (isset($_SERVER[ "HTTP_IF_MODIFIED_SINCE" ])) { $if_modified_since = preg_replace( "/;.*$/" , "" , $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ]); if (trim($_SERVER[ "HTTP_IF_NONE_MATCH" ]) == $etag && $if_modified_since == gmdate( "D, d MYH:i:s" , $time). " GMT" ) { header( "HTTP/1.0 304 Not modified" ); header( "CACHE-CONTROL: MAX-AGE={$expr}, MUST-REVALIDATE" ); exit; } } } … cmsCache_control($_SERVER[SCRIPT_FILENAME], filemtime($_SERVER[SCRIPT_FILENAME])); // , * This source code was highlighted with Source Code Highlighter .



  3. session_start(); // - function cmsCache_control($file, $time) { $etag = md5_file($file); $expr = 60 * 60 * 24 * 7; header( "ETAG: " . $etag); header( "LAST-MODIFIED: " . gmdate( "D, d MYH:i:s" , $time) . " GMT" ); header( "CACHE-CONTROL: " ); header( "PRAGMA: " ); header( "EXPIRES: " ); if (isset($_SERVER[ "HTTP_IF_MODIFIED_SINCE" ])) { $if_modified_since = preg_replace( "/;.*$/" , "" , $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ]); if (trim($_SERVER[ "HTTP_IF_NONE_MATCH" ]) == $etag && $if_modified_since == gmdate( "D, d MYH:i:s" , $time). " GMT" ) { header( "HTTP/1.0 304 Not modified" ); header( "CACHE-CONTROL: MAX-AGE={$expr}, MUST-REVALIDATE" ); exit; } } } … cmsCache_control($_SERVER[SCRIPT_FILENAME], filemtime($_SERVER[SCRIPT_FILENAME])); // , * This source code was highlighted with Source Code Highlighter .



  4. session_start(); // - function cmsCache_control($file, $time) { $etag = md5_file($file); $expr = 60 * 60 * 24 * 7; header( "ETAG: " . $etag); header( "LAST-MODIFIED: " . gmdate( "D, d MYH:i:s" , $time) . " GMT" ); header( "CACHE-CONTROL: " ); header( "PRAGMA: " ); header( "EXPIRES: " ); if (isset($_SERVER[ "HTTP_IF_MODIFIED_SINCE" ])) { $if_modified_since = preg_replace( "/;.*$/" , "" , $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ]); if (trim($_SERVER[ "HTTP_IF_NONE_MATCH" ]) == $etag && $if_modified_since == gmdate( "D, d MYH:i:s" , $time). " GMT" ) { header( "HTTP/1.0 304 Not modified" ); header( "CACHE-CONTROL: MAX-AGE={$expr}, MUST-REVALIDATE" ); exit; } } } … cmsCache_control($_SERVER[SCRIPT_FILENAME], filemtime($_SERVER[SCRIPT_FILENAME])); // , * This source code was highlighted with Source Code Highlighter .



  5. session_start(); // - function cmsCache_control($file, $time) { $etag = md5_file($file); $expr = 60 * 60 * 24 * 7; header( "ETAG: " . $etag); header( "LAST-MODIFIED: " . gmdate( "D, d MYH:i:s" , $time) . " GMT" ); header( "CACHE-CONTROL: " ); header( "PRAGMA: " ); header( "EXPIRES: " ); if (isset($_SERVER[ "HTTP_IF_MODIFIED_SINCE" ])) { $if_modified_since = preg_replace( "/;.*$/" , "" , $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ]); if (trim($_SERVER[ "HTTP_IF_NONE_MATCH" ]) == $etag && $if_modified_since == gmdate( "D, d MYH:i:s" , $time). " GMT" ) { header( "HTTP/1.0 304 Not modified" ); header( "CACHE-CONTROL: MAX-AGE={$expr}, MUST-REVALIDATE" ); exit; } } } … cmsCache_control($_SERVER[SCRIPT_FILENAME], filemtime($_SERVER[SCRIPT_FILENAME])); // , * This source code was highlighted with Source Code Highlighter .



  6. session_start(); // - function cmsCache_control($file, $time) { $etag = md5_file($file); $expr = 60 * 60 * 24 * 7; header( "ETAG: " . $etag); header( "LAST-MODIFIED: " . gmdate( "D, d MYH:i:s" , $time) . " GMT" ); header( "CACHE-CONTROL: " ); header( "PRAGMA: " ); header( "EXPIRES: " ); if (isset($_SERVER[ "HTTP_IF_MODIFIED_SINCE" ])) { $if_modified_since = preg_replace( "/;.*$/" , "" , $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ]); if (trim($_SERVER[ "HTTP_IF_NONE_MATCH" ]) == $etag && $if_modified_since == gmdate( "D, d MYH:i:s" , $time). " GMT" ) { header( "HTTP/1.0 304 Not modified" ); header( "CACHE-CONTROL: MAX-AGE={$expr}, MUST-REVALIDATE" ); exit; } } } … cmsCache_control($_SERVER[SCRIPT_FILENAME], filemtime($_SERVER[SCRIPT_FILENAME])); // , * This source code was highlighted with Source Code Highlighter .



  7. session_start(); // - function cmsCache_control($file, $time) { $etag = md5_file($file); $expr = 60 * 60 * 24 * 7; header( "ETAG: " . $etag); header( "LAST-MODIFIED: " . gmdate( "D, d MYH:i:s" , $time) . " GMT" ); header( "CACHE-CONTROL: " ); header( "PRAGMA: " ); header( "EXPIRES: " ); if (isset($_SERVER[ "HTTP_IF_MODIFIED_SINCE" ])) { $if_modified_since = preg_replace( "/;.*$/" , "" , $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ]); if (trim($_SERVER[ "HTTP_IF_NONE_MATCH" ]) == $etag && $if_modified_since == gmdate( "D, d MYH:i:s" , $time). " GMT" ) { header( "HTTP/1.0 304 Not modified" ); header( "CACHE-CONTROL: MAX-AGE={$expr}, MUST-REVALIDATE" ); exit; } } } … cmsCache_control($_SERVER[SCRIPT_FILENAME], filemtime($_SERVER[SCRIPT_FILENAME])); // , * This source code was highlighted with Source Code Highlighter .



  8. session_start(); // - function cmsCache_control($file, $time) { $etag = md5_file($file); $expr = 60 * 60 * 24 * 7; header( "ETAG: " . $etag); header( "LAST-MODIFIED: " . gmdate( "D, d MYH:i:s" , $time) . " GMT" ); header( "CACHE-CONTROL: " ); header( "PRAGMA: " ); header( "EXPIRES: " ); if (isset($_SERVER[ "HTTP_IF_MODIFIED_SINCE" ])) { $if_modified_since = preg_replace( "/;.*$/" , "" , $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ]); if (trim($_SERVER[ "HTTP_IF_NONE_MATCH" ]) == $etag && $if_modified_since == gmdate( "D, d MYH:i:s" , $time). " GMT" ) { header( "HTTP/1.0 304 Not modified" ); header( "CACHE-CONTROL: MAX-AGE={$expr}, MUST-REVALIDATE" ); exit; } } } … cmsCache_control($_SERVER[SCRIPT_FILENAME], filemtime($_SERVER[SCRIPT_FILENAME])); // , * This source code was highlighted with Source Code Highlighter .



  9. session_start(); // - function cmsCache_control($file, $time) { $etag = md5_file($file); $expr = 60 * 60 * 24 * 7; header( "ETAG: " . $etag); header( "LAST-MODIFIED: " . gmdate( "D, d MYH:i:s" , $time) . " GMT" ); header( "CACHE-CONTROL: " ); header( "PRAGMA: " ); header( "EXPIRES: " ); if (isset($_SERVER[ "HTTP_IF_MODIFIED_SINCE" ])) { $if_modified_since = preg_replace( "/;.*$/" , "" , $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ]); if (trim($_SERVER[ "HTTP_IF_NONE_MATCH" ]) == $etag && $if_modified_since == gmdate( "D, d MYH:i:s" , $time). " GMT" ) { header( "HTTP/1.0 304 Not modified" ); header( "CACHE-CONTROL: MAX-AGE={$expr}, MUST-REVALIDATE" ); exit; } } } … cmsCache_control($_SERVER[SCRIPT_FILENAME], filemtime($_SERVER[SCRIPT_FILENAME])); // , * This source code was highlighted with Source Code Highlighter .



  10. session_start(); // - function cmsCache_control($file, $time) { $etag = md5_file($file); $expr = 60 * 60 * 24 * 7; header( "ETAG: " . $etag); header( "LAST-MODIFIED: " . gmdate( "D, d MYH:i:s" , $time) . " GMT" ); header( "CACHE-CONTROL: " ); header( "PRAGMA: " ); header( "EXPIRES: " ); if (isset($_SERVER[ "HTTP_IF_MODIFIED_SINCE" ])) { $if_modified_since = preg_replace( "/;.*$/" , "" , $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ]); if (trim($_SERVER[ "HTTP_IF_NONE_MATCH" ]) == $etag && $if_modified_since == gmdate( "D, d MYH:i:s" , $time). " GMT" ) { header( "HTTP/1.0 304 Not modified" ); header( "CACHE-CONTROL: MAX-AGE={$expr}, MUST-REVALIDATE" ); exit; } } } … cmsCache_control($_SERVER[SCRIPT_FILENAME], filemtime($_SERVER[SCRIPT_FILENAME])); // , * This source code was highlighted with Source Code Highlighter .



  11. session_start(); // - function cmsCache_control($file, $time) { $etag = md5_file($file); $expr = 60 * 60 * 24 * 7; header( "ETAG: " . $etag); header( "LAST-MODIFIED: " . gmdate( "D, d MYH:i:s" , $time) . " GMT" ); header( "CACHE-CONTROL: " ); header( "PRAGMA: " ); header( "EXPIRES: " ); if (isset($_SERVER[ "HTTP_IF_MODIFIED_SINCE" ])) { $if_modified_since = preg_replace( "/;.*$/" , "" , $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ]); if (trim($_SERVER[ "HTTP_IF_NONE_MATCH" ]) == $etag && $if_modified_since == gmdate( "D, d MYH:i:s" , $time). " GMT" ) { header( "HTTP/1.0 304 Not modified" ); header( "CACHE-CONTROL: MAX-AGE={$expr}, MUST-REVALIDATE" ); exit; } } } … cmsCache_control($_SERVER[SCRIPT_FILENAME], filemtime($_SERVER[SCRIPT_FILENAME])); // , * This source code was highlighted with Source Code Highlighter .



  12. session_start(); // - function cmsCache_control($file, $time) { $etag = md5_file($file); $expr = 60 * 60 * 24 * 7; header( "ETAG: " . $etag); header( "LAST-MODIFIED: " . gmdate( "D, d MYH:i:s" , $time) . " GMT" ); header( "CACHE-CONTROL: " ); header( "PRAGMA: " ); header( "EXPIRES: " ); if (isset($_SERVER[ "HTTP_IF_MODIFIED_SINCE" ])) { $if_modified_since = preg_replace( "/;.*$/" , "" , $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ]); if (trim($_SERVER[ "HTTP_IF_NONE_MATCH" ]) == $etag && $if_modified_since == gmdate( "D, d MYH:i:s" , $time). " GMT" ) { header( "HTTP/1.0 304 Not modified" ); header( "CACHE-CONTROL: MAX-AGE={$expr}, MUST-REVALIDATE" ); exit; } } } … cmsCache_control($_SERVER[SCRIPT_FILENAME], filemtime($_SERVER[SCRIPT_FILENAME])); // , * This source code was highlighted with Source Code Highlighter .



  13. session_start(); // - function cmsCache_control($file, $time) { $etag = md5_file($file); $expr = 60 * 60 * 24 * 7; header( "ETAG: " . $etag); header( "LAST-MODIFIED: " . gmdate( "D, d MYH:i:s" , $time) . " GMT" ); header( "CACHE-CONTROL: " ); header( "PRAGMA: " ); header( "EXPIRES: " ); if (isset($_SERVER[ "HTTP_IF_MODIFIED_SINCE" ])) { $if_modified_since = preg_replace( "/;.*$/" , "" , $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ]); if (trim($_SERVER[ "HTTP_IF_NONE_MATCH" ]) == $etag && $if_modified_since == gmdate( "D, d MYH:i:s" , $time). " GMT" ) { header( "HTTP/1.0 304 Not modified" ); header( "CACHE-CONTROL: MAX-AGE={$expr}, MUST-REVALIDATE" ); exit; } } } … cmsCache_control($_SERVER[SCRIPT_FILENAME], filemtime($_SERVER[SCRIPT_FILENAME])); // , * This source code was highlighted with Source Code Highlighter .



  14. session_start(); // - function cmsCache_control($file, $time) { $etag = md5_file($file); $expr = 60 * 60 * 24 * 7; header( "ETAG: " . $etag); header( "LAST-MODIFIED: " . gmdate( "D, d MYH:i:s" , $time) . " GMT" ); header( "CACHE-CONTROL: " ); header( "PRAGMA: " ); header( "EXPIRES: " ); if (isset($_SERVER[ "HTTP_IF_MODIFIED_SINCE" ])) { $if_modified_since = preg_replace( "/;.*$/" , "" , $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ]); if (trim($_SERVER[ "HTTP_IF_NONE_MATCH" ]) == $etag && $if_modified_since == gmdate( "D, d MYH:i:s" , $time). " GMT" ) { header( "HTTP/1.0 304 Not modified" ); header( "CACHE-CONTROL: MAX-AGE={$expr}, MUST-REVALIDATE" ); exit; } } } … cmsCache_control($_SERVER[SCRIPT_FILENAME], filemtime($_SERVER[SCRIPT_FILENAME])); // , * This source code was highlighted with Source Code Highlighter .



  15. session_start(); // - function cmsCache_control($file, $time) { $etag = md5_file($file); $expr = 60 * 60 * 24 * 7; header( "ETAG: " . $etag); header( "LAST-MODIFIED: " . gmdate( "D, d MYH:i:s" , $time) . " GMT" ); header( "CACHE-CONTROL: " ); header( "PRAGMA: " ); header( "EXPIRES: " ); if (isset($_SERVER[ "HTTP_IF_MODIFIED_SINCE" ])) { $if_modified_since = preg_replace( "/;.*$/" , "" , $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ]); if (trim($_SERVER[ "HTTP_IF_NONE_MATCH" ]) == $etag && $if_modified_since == gmdate( "D, d MYH:i:s" , $time). " GMT" ) { header( "HTTP/1.0 304 Not modified" ); header( "CACHE-CONTROL: MAX-AGE={$expr}, MUST-REVALIDATE" ); exit; } } } … cmsCache_control($_SERVER[SCRIPT_FILENAME], filemtime($_SERVER[SCRIPT_FILENAME])); // , * This source code was highlighted with Source Code Highlighter .



  16. session_start(); // - function cmsCache_control($file, $time) { $etag = md5_file($file); $expr = 60 * 60 * 24 * 7; header( "ETAG: " . $etag); header( "LAST-MODIFIED: " . gmdate( "D, d MYH:i:s" , $time) . " GMT" ); header( "CACHE-CONTROL: " ); header( "PRAGMA: " ); header( "EXPIRES: " ); if (isset($_SERVER[ "HTTP_IF_MODIFIED_SINCE" ])) { $if_modified_since = preg_replace( "/;.*$/" , "" , $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ]); if (trim($_SERVER[ "HTTP_IF_NONE_MATCH" ]) == $etag && $if_modified_since == gmdate( "D, d MYH:i:s" , $time). " GMT" ) { header( "HTTP/1.0 304 Not modified" ); header( "CACHE-CONTROL: MAX-AGE={$expr}, MUST-REVALIDATE" ); exit; } } } … cmsCache_control($_SERVER[SCRIPT_FILENAME], filemtime($_SERVER[SCRIPT_FILENAME])); // , * This source code was highlighted with Source Code Highlighter .



  17. session_start(); // - function cmsCache_control($file, $time) { $etag = md5_file($file); $expr = 60 * 60 * 24 * 7; header( "ETAG: " . $etag); header( "LAST-MODIFIED: " . gmdate( "D, d MYH:i:s" , $time) . " GMT" ); header( "CACHE-CONTROL: " ); header( "PRAGMA: " ); header( "EXPIRES: " ); if (isset($_SERVER[ "HTTP_IF_MODIFIED_SINCE" ])) { $if_modified_since = preg_replace( "/;.*$/" , "" , $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ]); if (trim($_SERVER[ "HTTP_IF_NONE_MATCH" ]) == $etag && $if_modified_since == gmdate( "D, d MYH:i:s" , $time). " GMT" ) { header( "HTTP/1.0 304 Not modified" ); header( "CACHE-CONTROL: MAX-AGE={$expr}, MUST-REVALIDATE" ); exit; } } } … cmsCache_control($_SERVER[SCRIPT_FILENAME], filemtime($_SERVER[SCRIPT_FILENAME])); // , * This source code was highlighted with Source Code Highlighter .



  18. session_start(); // - function cmsCache_control($file, $time) { $etag = md5_file($file); $expr = 60 * 60 * 24 * 7; header( "ETAG: " . $etag); header( "LAST-MODIFIED: " . gmdate( "D, d MYH:i:s" , $time) . " GMT" ); header( "CACHE-CONTROL: " ); header( "PRAGMA: " ); header( "EXPIRES: " ); if (isset($_SERVER[ "HTTP_IF_MODIFIED_SINCE" ])) { $if_modified_since = preg_replace( "/;.*$/" , "" , $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ]); if (trim($_SERVER[ "HTTP_IF_NONE_MATCH" ]) == $etag && $if_modified_since == gmdate( "D, d MYH:i:s" , $time). " GMT" ) { header( "HTTP/1.0 304 Not modified" ); header( "CACHE-CONTROL: MAX-AGE={$expr}, MUST-REVALIDATE" ); exit; } } } … cmsCache_control($_SERVER[SCRIPT_FILENAME], filemtime($_SERVER[SCRIPT_FILENAME])); // , * This source code was highlighted with Source Code Highlighter .



  19. session_start(); // - function cmsCache_control($file, $time) { $etag = md5_file($file); $expr = 60 * 60 * 24 * 7; header( "ETAG: " . $etag); header( "LAST-MODIFIED: " . gmdate( "D, d MYH:i:s" , $time) . " GMT" ); header( "CACHE-CONTROL: " ); header( "PRAGMA: " ); header( "EXPIRES: " ); if (isset($_SERVER[ "HTTP_IF_MODIFIED_SINCE" ])) { $if_modified_since = preg_replace( "/;.*$/" , "" , $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ]); if (trim($_SERVER[ "HTTP_IF_NONE_MATCH" ]) == $etag && $if_modified_since == gmdate( "D, d MYH:i:s" , $time). " GMT" ) { header( "HTTP/1.0 304 Not modified" ); header( "CACHE-CONTROL: MAX-AGE={$expr}, MUST-REVALIDATE" ); exit; } } } … cmsCache_control($_SERVER[SCRIPT_FILENAME], filemtime($_SERVER[SCRIPT_FILENAME])); // , * This source code was highlighted with Source Code Highlighter .



  20. session_start(); // - function cmsCache_control($file, $time) { $etag = md5_file($file); $expr = 60 * 60 * 24 * 7; header( "ETAG: " . $etag); header( "LAST-MODIFIED: " . gmdate( "D, d MYH:i:s" , $time) . " GMT" ); header( "CACHE-CONTROL: " ); header( "PRAGMA: " ); header( "EXPIRES: " ); if (isset($_SERVER[ "HTTP_IF_MODIFIED_SINCE" ])) { $if_modified_since = preg_replace( "/;.*$/" , "" , $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ]); if (trim($_SERVER[ "HTTP_IF_NONE_MATCH" ]) == $etag && $if_modified_since == gmdate( "D, d MYH:i:s" , $time). " GMT" ) { header( "HTTP/1.0 304 Not modified" ); header( "CACHE-CONTROL: MAX-AGE={$expr}, MUST-REVALIDATE" ); exit; } } } … cmsCache_control($_SERVER[SCRIPT_FILENAME], filemtime($_SERVER[SCRIPT_FILENAME])); // , * This source code was highlighted with Source Code Highlighter .



  21. session_start(); // - function cmsCache_control($file, $time) { $etag = md5_file($file); $expr = 60 * 60 * 24 * 7; header( "ETAG: " . $etag); header( "LAST-MODIFIED: " . gmdate( "D, d MYH:i:s" , $time) . " GMT" ); header( "CACHE-CONTROL: " ); header( "PRAGMA: " ); header( "EXPIRES: " ); if (isset($_SERVER[ "HTTP_IF_MODIFIED_SINCE" ])) { $if_modified_since = preg_replace( "/;.*$/" , "" , $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ]); if (trim($_SERVER[ "HTTP_IF_NONE_MATCH" ]) == $etag && $if_modified_since == gmdate( "D, d MYH:i:s" , $time). " GMT" ) { header( "HTTP/1.0 304 Not modified" ); header( "CACHE-CONTROL: MAX-AGE={$expr}, MUST-REVALIDATE" ); exit; } } } … cmsCache_control($_SERVER[SCRIPT_FILENAME], filemtime($_SERVER[SCRIPT_FILENAME])); // , * This source code was highlighted with Source Code Highlighter .



  22. session_start(); // - function cmsCache_control($file, $time) { $etag = md5_file($file); $expr = 60 * 60 * 24 * 7; header( "ETAG: " . $etag); header( "LAST-MODIFIED: " . gmdate( "D, d MYH:i:s" , $time) . " GMT" ); header( "CACHE-CONTROL: " ); header( "PRAGMA: " ); header( "EXPIRES: " ); if (isset($_SERVER[ "HTTP_IF_MODIFIED_SINCE" ])) { $if_modified_since = preg_replace( "/;.*$/" , "" , $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ]); if (trim($_SERVER[ "HTTP_IF_NONE_MATCH" ]) == $etag && $if_modified_since == gmdate( "D, d MYH:i:s" , $time). " GMT" ) { header( "HTTP/1.0 304 Not modified" ); header( "CACHE-CONTROL: MAX-AGE={$expr}, MUST-REVALIDATE" ); exit; } } } … cmsCache_control($_SERVER[SCRIPT_FILENAME], filemtime($_SERVER[SCRIPT_FILENAME])); // , * This source code was highlighted with Source Code Highlighter .



session_start(); // - function cmsCache_control($file, $time) { $etag = md5_file($file); $expr = 60 * 60 * 24 * 7; header( "ETAG: " . $etag); header( "LAST-MODIFIED: " . gmdate( "D, d MYH:i:s" , $time) . " GMT" ); header( "CACHE-CONTROL: " ); header( "PRAGMA: " ); header( "EXPIRES: " ); if (isset($_SERVER[ "HTTP_IF_MODIFIED_SINCE" ])) { $if_modified_since = preg_replace( "/;.*$/" , "" , $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ]); if (trim($_SERVER[ "HTTP_IF_NONE_MATCH" ]) == $etag && $if_modified_since == gmdate( "D, d MYH:i:s" , $time). " GMT" ) { header( "HTTP/1.0 304 Not modified" ); header( "CACHE-CONTROL: MAX-AGE={$expr}, MUST-REVALIDATE" ); exit; } } } … cmsCache_control($_SERVER[SCRIPT_FILENAME], filemtime($_SERVER[SCRIPT_FILENAME])); // , * This source code was highlighted with Source Code Highlighter .







スクリプトは特別なことは何もしません-ヘッダーに変更日を設定するだけで、キャッシュされたファイルの日付の標準リクエストヘッダーに従います。



唯一の追加は、 filemtime()の代わりに、別の任意の日付も使用できることです。スクリプトでは、最新のファイルが変更された日付を使用しました。



PS上記のフラグメントは、セッションを考慮するために私によって修正されましたが、コード自体はhttp://ru2.php.net/manual/ru/function.header.php#85146http://foxweb.net.ruから取得されます。 /texts/43.htmアンチショックの同志のコメント)。



All Articles