php - Include File Get New Content Last Changed
Get the solution ↓↓↓I've created a file called "settings.php"
and inside settings.php
<?php
return '123';
?>
And in index.php I updated the content of settings.php using file_put_contents
$config = '1234';
file_put_contents('settings.php', '<?php return ' . var_export($config), true) . ';');
After successfully updated the content, in index.php I call the settings.php
$config = include(BASEPATH.'settings.php');
But after I print_r, the result is
123
and after sometimes waiting (maybe 5 up to 15 seconds), I do refresh page again and the content changed to
1234
The problem is, why the updated content not directly changed after I refresh the page? how to get the newly updated content from settings.php after I change its content.
Answer
Solution:
Check what cache solution is on your server thru phpinfo().
Then you can search solution.
In first you can try this if opcache solution is installed on your server:
if (function_exists('opcache_invalidate')) {
opcache_invalidate('second.php');//Reset file cache
}
or this for normal raw files:
clearstatcache();
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: the payload is invalid.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.