PHP No Cache for Development
Posted: Sat Jul 04, 2020 7:50 pm
PHP No Cache for Development.
For a while now I have just been sticking with the issue of updating a PHP file and having to wait until the next minute for the change to update in the browser (while refreshing every second).
But finally I figured out the cache problem. For development and testing purposes. I can now update a php file multiple times in the same minute and it will show the latest changes in the browser. Try to use this PHP code:
So in my code. I do a require() settings.php file. And in settings.php I can place this code in it. I did try to do a ini_set() and opcache_enable to false but it still seem to run the cached code.
Here is my sloppy test code I was working with.
For a while now I have just been sticking with the issue of updating a PHP file and having to wait until the next minute for the change to update in the browser (while refreshing every second).
But finally I figured out the cache problem. For development and testing purposes. I can now update a php file multiple times in the same minute and it will show the latest changes in the browser. Try to use this PHP code:
Code: Select all
opcache_reset();
Here is my sloppy test code I was working with.
Code: Select all
<?php
if ($_SERVER['HTTP_HOST'] == '127.0.0.1') {
define('PHPFLARE_DEBUGMODE',true);
}
if (defined('PHPFLARE_DEBUGMODE')&&PHPFLARE_DEBUGMODE == true) {
//lets no cache for development testing
//header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
//header("Cache-Control: post-check=0, pre-check=0", false);
//header("Pragma: no-cache");
/*$seconds_to_cache = -(60*60*24*365);
$ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT";
header("Expires: $ts");
header("Pragma: cache");
header("Cache-Control: max-age=$seconds_to_cache");*/
opcache_reset();
//ini_set('opcache.revalidate_freq',1);
echo "<pre>\n";
echo "cache<br />\n";
echo "cache2345678<br />\n"; //I was changing this variable to try different no cache things.
echo time();
//echo "<pre>";var_dump(ini_get_all());
//I only removed a var_dump() opcode cache enable to see if it was on
echo "\n\n";
var_dump(opcache_get_configuration());
echo "\n\n";
var_dump(opcache_get_status());
exit();
}
?>