Problem:
Hello, sometimes, when I update code in my Symfony app, the changes aren't visible in the browser.
- clearing cache (
php bin/console cache:clear) won't help. - removing var/cache/ won't help too.
- clearing Opcache (
opcache_reset();apcu_clear_cache();) from the console and from the browser won't help too.
What is more, if I add some code in the controller, e.g.:
<?php
echo '!!!';
exit;
This code isn't executed, the website seems to serve some old file content.
If I made some changes to twig files, it works, and changes are served.
Suspicious:
After a lot of debugging, I think that the issue might be because of using Opcache (and/or preload.php).
I have Opcache and preload.php enabled in php.ini like this:
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=2
opcache.fast_shutdown=1
opcache.enable_cli=1
opcache.preload=/var/www/html/config/preload.php
opcache.preload_user=www-data
Other suspicious:
Other suspicious is caching in Symfony, which is used in application.
Our application uses Symfony request caching, e.g.:
class HomepageController extends AbstractController
{
private const MAX_LIMIT_ARTICLES_PER_CATEGORY = 9;
public function __invoke(Request $request): Response
{
$articles = [];
// get articles from database... (removed)
$response = new Response();
$content = $this->renderView('Website/homepage.html.twig', ['articles' => $articles]);
$response->setPublic();
$response->setEtag(md5($content));
if ($response->isNotModified($request)) {
return $response;
}
$response->setContent($content);
return $response;
}
But even here, when adding some exit before exit; $response = new Response(); it won't exit, the old content of the file is served.
Info:
What works? If I change in .env.local variable from: APP_DEBUG=false the file is served correctly, but when I change it back to the APP_DEBUG=true the problem return, and the previous version of the PHP file is served.
Sollution?
I would appreciate any suggestions on what can cause those problems.
If it is Opcache fault, how can I revalidate all the cached files at once?