Symfony独特的缓存bug

When I change the controller i do not see any changes. Only after two minutes automatically changes show on the website. I work using netbeans, run as remote web site(FTP). If I change the controller using directly FileZilla is the same. I use dev environment of course.

Now please don't tell me delete

var/cache folder

or use php app/console

cache:clear --env=prod --no-debug

This help once and provoke error from the image. And then i have to wait 2 minutes. After 2 minutes that error automatically disappear. My changes are visible but if i change the controller again, i have the same problem. Now again delete var/cache..wait two minutes, changes are visible. I can't work like that. Twig is ok, this reffering only php.

IMAGE

enter image description here

IMAGE

My web/app_dev.php

$loader = require __DIR__.'/../app/autoload.php';
Debug::enable();

$kernel = new AppKernel('dev', true);
//$kernel->loadClassCache();
Request::setTrustedHosts(array('^(.+\.)?finearts.klitom1.sldc.pl$')); 
$request = Request::createFromGlobals();

$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

Any ideas?

The most probable reason: You have a race condition rebuilding the cache on your server due to concurrent requests. Your hosting/server has limited cpu (php-fpm process) assigned to your site and a script timeout quite low that does not give enough time to rebuild completely the cache in one request.

If you want to keep doing live coding you should follow the following steps:

  1. Update .htaccess to setup your site in maintenance mode so you do not get external traffic and only you access to the site
  2. Upload your code
  3. Run app/console cache:clear --no-warmup --env prod
  4. Run app/console cache:warmup --env prod #this makes symfony rebuild the cache via CLI instead of php-fpm
  5. Disable maintenance mode

This is alot of work and it will slow down as you already mentioned but it will make it faster to get symfony up and running again.

My recommended steps:

  1. Never do live coding on a production server. Setup your machine for web development with: https://symfony.com/doc/current/setup/homestead.html or http://phansible.com/ or Docker
  2. Setup a one step deployment process. Example: https://deployer.org/ or https://github.com/capistrano/capistrano if you want more complex setups I can give you more, those are the most basic ones.
  3. Use a repository to store your code bitbucket, github, gitlab, phabricator ...