Symfony ESI Cache / Surrogate Listener Issue

704 views Asked by At

I've got a product I've deployed to a live Ubuntu 14.04 server, which works fine in app_dev. However, when I run it in app, it brings up a 503 error, with the below in the app log file:

I've got the exact same code in a Vagrant setup, same OS version and it works fine in both app and app_dev

Has anyone come across this before?

Symfony 2.7.0 / Ubuntu 14.04 / Distro PHP / mySQL - Tried clearing the cache & reinstalling all composer packages.

[2015-06-09 16:36:43] request.INFO: Matched route "fos_user_security_login". {"route_parameters":{"_controller":"FOS\UserBundle\Controller\SecurityController::loginAction","_route":"fos_user_security_login"},"request_uri":"http://xxxx/app.php/login"} []

[2015-06-09 16:36:43] security.INFO: Populated the TokenStorage with an anonymous Token. [] []

[2015-06-09 16:36:43] request.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\ContextErrorException: "Catchable Fatal Error: Argument 1 passed to Symfony\Component\HttpKernel\EventListener\SurrogateListener::__construct() must be an instance of Symfony\Component\HttpKernel\HttpCache\SurrogateInterface, instance of Symfony\Component\HttpKernel\HttpCache\Esi given, called in /var/www/xxxx/app/cache/prod/appProdProjectContainer.php on line 557 and defined" at /var/www/xxxx/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/EventListener/SurrogateListener.php line 33 {"exception":"[object] (Symfony\Component\Debug\Exception\ContextErrorException(code: 0): Catchable Fatal Error: Argument 1 passed to Symfony\Component\HttpKernel\EventListener\SurrogateListener::__construct() must be an instance of Symfony\Component\HttpKernel\HttpCache\SurrogateInterface, instance of Symfony\Component\HttpKernel\HttpCache\Esi given, called in /var/www/xxxx/app/cache/prod/appProdProjectContainer.php on line 557 and defined at /var/www/xxxx/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/EventListener/SurrogateListener.php:33)"} []

(To those who suggest code formatting the log lines, it formats them onto a single line, which basically means having to scroll them to read them, which is worse than above).

1

There are 1 answers

3
Steve Childs On

sigh - Always the case. You spend half an hour trying to solve it, you then post the question on SO and within 2 minutes you solve it yourself!

Thinking about the difference in setup between the vagrant setup is that the live box has more than 1 project active and then BINGO! it occurred to me.

The app environment uses APC to cache the classes and yes, both projects had the same apc cache key!

A quick key change and cache rebuild and its all fixed!

I thought I'd answer this incase anyone else had a similar issue.

Update:

A tweak to app.php....

// As APC requires a unique key prefix, we'll use the directory above     web, which will be unique.
$curdir = pathinfo(getcwd());
$curdir = basename($curdir['dirname']);
$loader = new ApcClassLoader($curdir . '_', $loader);
$loader->register(true);

This uses the folder above the cwd (usually apache's doc root) to prefix the key, as long as they're unique (it should be), then multiple cache's won't clash.