Symfony comes with a built-in reverse proxy written in PHP, known as
HttpCache. While it is certainly less efficient
than using Varnish or Nginx, it can still provide considerable performance
gains over an installation that is not cached at all. It can be useful for
running an application on shared hosting for instance
(see the Symfony HttpCache documentation).
You can use features of this library with the Symfony
HttpCache. The basic
concept is to use event listeners on the HttpCache class.
Symfony HttpCache support is currently limited to following features:
- Cache Tags
- User Context
BAN operations are not supported.
Event Dispatching HttpCache¶
You need to adjust your
AppCache to support event handling and register the
cache event listeners for the functionality you want to use.
To adjust your cache kernel, follow the instructions in the FOSHttpCache Symfony Cache documentation section.
Since Symfony 2.8, the class cache (
classes.php) is compiled even in
console mode by an optional warmer (
ClassCacheCacheWarmer). This can
produce conflicting results with the regular web entry points, because the
class cache may contain definitions (such as the subscribers above) that
are loaded before the class cache itself; leading to redeclaration fatal
There are two workarounds:
Disable class cache warming in console mode with e.g. a compiler pass:
Force loading of all classes and interfaced used by the
app/consoleto make the class cache omit those classes. The simplest way to achieve this is to call
interface_existswith each of them.
Each cache feature has its own event listener. The listeners are provided by the FOSHttpCache library. You can find the documentation for those listeners in the FOSHttpCache Symfony Cache documentation section.
Optimization for Single Server Installations¶
If your application runs on one single server, you can use the kernel
dispatcher to directly call the
HttpCache rather than sending an actual
web request. This is more efficient, and you don’t need to configure the server
The FOSHttpCache Symfony Proxy Client documentation section
explains how to adjust your bootstrap - you will need to do this in both
Once your bootstrapping is adjusted, set the configuration option