Search code examples
symfonybrowserhttp-caching

Symfony2 ESI bug browser cache


I am using ESI caching at my web; there were working fine and today I cleared APC cache and sf2 cache and I see everything OK. But some people can't see the esi panels etc.

Why is this, and how to fix it? I don't understand why I and some friends can see it well and other people cannot?

Using symfony 2.1.7

Rendering this way:

$response=new Response();
$response= $this->render('HomePageBundle:Default:index.html.twig', array(...
$response->setPrivate(true);
$response->setMaxAge(300);

return $response;

My web/app.php file

require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';
require_once __DIR__.'/../app/AppCache.php';

$loader = new ApcClassLoader('tb_sf2', $loader);
$loader->register(true);

$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();

// wrap the default AppKernel with the AppCache one
$kernel = new AppCache($kernel);

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

But if it would be an error I would not see the esi panels too, right?

I cleared the cache again some time (maybe 30mins later) one said:

Now I can see the left menu, but the top, still nothing there

I cleared the log and than my friend made refresh... this log was added for each ESI panel:

[2013-05-27 23:03:17] request.INFO: Matched route "home_page_homepage" (parameters: "_controller": "TB\HomePageBundle\Controller\DefaultController::indexAction", "_route": "home_page_homepage") [] []
[2013-05-27 23:03:17] app.INFO: Locale Query Guessing Service Loaded [] []
[2013-05-27 23:03:17] app.INFO: Locale has not been identified by the Query guessing service [] []
[2013-05-27 23:03:17] app.INFO: Locale Session Guessing Service Loaded [] []
[2013-05-27 23:03:17] app.INFO: Locale has been identified by guessing service: ( Session ) [] []
[2013-05-27 23:03:17] app.INFO: Setting [ en ] as defaultLocale for the Request [] []
[2013-05-27 23:03:17] security.DEBUG: Read SecurityContext from the session [] []
[2013-05-27 23:03:17] security.DEBUG: Reloading user from user provider. [] []
[2013-05-27 23:03:17] security.DEBUG: Username "MbrunoM" was reloaded from user provider. [] []
[2013-05-27 23:03:18] security.DEBUG: Write SecurityContext in the session [] []
[2013-05-27 23:03:18] request.INFO: Matched route "notifications_box_esi" (parameters: "_controller": "TB\HomePageBundle\Controller\DefaultController::notificationsBoxEsiAction", "max": "10", "_route": "notifications_box_esi") [] []
[2013-05-27 23:03:18] app.INFO: Locale Query Guessing Service Loaded [] []
[2013-05-27 23:03:18] app.INFO: Locale has not been identified by the Query guessing service [] []

[2013-05-27 23:03:18] app.INFO: Locale Query Guessing Service Loaded [] []
[2013-05-27 23:03:18] app.INFO: Locale has not been identified by the Query guessing service [] []
[2013-05-27 23:03:18] app.INFO: Locale Session Guessing Service Loaded [] []
[2013-05-27 23:03:18] app.INFO: Locale has been identified by guessing service: ( Session ) [] []
[2013-05-27 23:03:18] app.INFO: Setting [ en ] as defaultLocale for the Request [] []
[2013-05-27 23:03:18] security.DEBUG: Read SecurityContext from the session [] []
[2013-05-27 23:03:18] security.DEBUG: Reloading user from user provider. [] []
[2013-05-27 23:03:18] security.DEBUG: Username "MbrunoM" was reloaded from user provider. [] []
[2013-05-27 23:03:18] security.DEBUG: Access is denied (and user is neither anonymous, nor remember-me) by "/var/www/domain.com/framework/vendor/symfony/symfony/src/Symfony/Component/Security/Http/Firewall/AccessListener.php" at line 70 [] []
[2013-05-27 23:03:18] security.DEBUG: Access is denied (and user is neither anonymous, nor remember-me) by "/var/www/domain.com/framework/vendor/symfony/symfony/src/Symfony/Component/Security/Http/Firewall/AccessListener.php" at line 70 [] []

Solution

  • Make sure your users are allowed to gain access to the ESI route by your firewall.

    There might be an error in your Firewall configuration. Your user does not have access granted to route '*notifications_box_esi*'. The interesting line in your debug log is this one:

    security.DEBUG: Access is denied (and user is neither anonymous, nor remember-me) by "/var/www/nonamepage/framework/vendor/symfony/symfony/src/Symfony/Component/Security/Http/Firewall/AccessListener.php" at line 70 [] [] [2013-05-27 23:03:18] security.
    

    You firewall allows or restricts access to certain routes/urls based on roles or an access-decision-manager.

    The configuration can be found in your security.yml:

    security:
    
        # ...
    
        access_control:
            - { path: ^/admin/users, roles: ROLE_SUPER_ADMIN }
            - { path: ^/admin, roles: ROLE_ADMIN }
    
        # ... or with an access decision manager
        firewalls:
            your_firewall_name:
                pattern:    ^/
                # ...
    

    You can check which roles a current user has with:

    $this->get('security.context')->getToken()->getUser()->getRoles();