PHP No Cache for Development

Post Reply
TzzSpaceFighter
Posts: 11
Joined: Wed Jun 03, 2020 7:53 pm

PHP No Cache for Development

Post by TzzSpaceFighter »

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:

Code: Select all

opcache_reset();
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.

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();
}
?>
2020-07-04 (2).png
2020-07-04 (2).png (120.58 KiB) Viewed 1766 times
TzzSpaceFighter
Posts: 11
Joined: Wed Jun 03, 2020 7:53 pm

Re: PHP No Cache for Development

Post by TzzSpaceFighter »

And for CSS cache problem. I set a variable in the url to include the version number. Something like:

Code: Select all

//This is not copy and paste code.
//Convert this to proper html.
//This is because phpbb fails. I will eventually build my own php forum script and won't have to deal with all the problems of other peoples php fail.

link rel=stylesheet href=css/phpflare.css?v=2
A tip. Don't try to edit posts in phpbb. Just create a new post/reply. Don't try to post any code, it will hack my website. Maybe try htmlentities your code first but I would rather build my own quality forum (will get to that eventually).
Post Reply