📜 ⬆️ ⬇️

Conventional caching

Today I decided to do what I had planned for a long time - to put the caching of scripts on my site. All the scripts are collected into a single file before being sent out and compressed with GZIP - everything seems to be smart, but there is a problem ... The browser desperately did not want to cache this output script.

It has been experimentally established that PHP sets the cache prohibition headers when using the session_start () function;

Here is an example of code that implements the specific file's caching (note the three header () functions that throw off extra headers):

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 .

')
The script does not do anything special - it simply puts the modification date in the header, and then keeps track of what the cached file has on the standard headers of the request.

The only addition - instead of filemtime (), you can also use another arbitrary date, in my script I used the date of the most recent file change.

PS The above fragment was modified by me to account for the session, but the code itself is taken from here: http://ru2.php.net/manual/ru/function.header.php#85146 , and also http://foxweb.net.ru /texts/43.htm (comments from friend antishock ).

Source: https://habr.com/ru/post/44906/


All Articles