I have the following test code in test.php:
<?php
$step = $_GET['step'];
switch($step) {
case 1:
include 'foo.php'; # line 5
file_put_contents('foo.php', '<?php print "bar\\n"; ?>');
header('Location: test.php?step=2');
break;
case 2:
print "step 2:\n";
include 'foo.php';
break;
}
?>
foo.php initially has the following content:
<?php print "foo\n"; ?>
When I call test.php?step=1 in my browser I would expect the following output:
step 2:
bar
But I get this output:
step 2:
foo
When I comment out the include in line 5, I get the desired result. The conclusion is, that PHP caches the content of foo.php. When I reload the page with step=2 I also get the desired result.
Now... why is this and how to avoid this?
Assuming you use OPcache, opcache.enable = 0
works.
A more efficient method is to use
opcache_invalidate ( string $script [, boolean $force = FALSE ] )
This will remove the cached version of the script from memory and force PHP to recompile.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With