Skip to content

Commit

Permalink
Merge branch '2.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed Jan 30, 2015
2 parents 714f630 + bc29584 commit 87eb36c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
2 changes: 1 addition & 1 deletion book/forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ That's it! Just three lines are needed to render the complete form:
Renders all the fields, which includes the field element itself, a label
and any validation error messages for the field.

``form_end()``
``form_end(form)``
Renders the end tag of the form and any fields that have not
yet been rendered, in case you rendered each field yourself. This is useful
for rendering hidden fields and taking advantage of the automatic
Expand Down
2 changes: 2 additions & 0 deletions book/http_cache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ This has two very reasonable consequences:
blog post). Caching them would prevent certain requests from hitting and
mutating your application.

.. _http-cache-defaults:

Caching Rules and Defaults
~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion book/internals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ The FrameworkBundle registers several listeners:

*Event Class*: :class:`Symfony\\Component\\HttpKernel\\Event\\FinishRequestEvent`

The purpose of this event is to to handle tasks that should be performed after
The purpose of this event is to handle tasks that should be performed after
the request has been handled but that do not need to modify the response.
Event listeners for the ``kernel.finish_request`` event are called in both
successful and exception cases.
Expand Down
4 changes: 2 additions & 2 deletions components/filesystem/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ endpoint for filesystem operations::
$fs = new Filesystem();

try {
$fs->mkdir('/tmp/random/dir/' . mt_rand());
$fs->mkdir('/tmp/random/dir/'.mt_rand());
} catch (IOExceptionInterface $e) {
echo "An error occurred while creating your directory at ".$e->getPath();
}
Expand All @@ -52,7 +52,7 @@ mkdir
~~~~~

:method:`Symfony\\Component\\Filesystem\\Filesystem::mkdir` creates a directory.
On posix filesystems, directories are created with a default mode value
On POSIX filesystems, directories are created with a default mode value
`0777`. You can use the second argument to set your own mode::

$fs->mkdir('/tmp/photos', 0700);
Expand Down
53 changes: 53 additions & 0 deletions cookbook/cache/varnish.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,57 @@ If the ``X-Forwarded-Port`` header is not set correctly, Symfony will append
the port where the PHP application is running when generating absolute URLs,
e.g. ``http://example.com:8080/my/path``.

Cookies and Caching
-------------------

By default, a sane caching proxy does not cache anything when a request is sent
with :ref:`cookies or a basic authentication header<http-cache-introduction>`.
This is because the content of the page is supposed to depend on the cookie
value or authentication header.

If you know for sure that the backend never uses sessions or basic
authentication, have varnish remove the corresponding header from requests to
prevent clients from bypassing the cache. In practice, you will need sessions
at least for some parts of the site, e.g. when using forms with
:ref:`CSRF Protection <forms-csrf>`. In this situation, make sure to only
start a session when actually needed, and clear the session when it is no
longer needed. Alternatively, you can look into :doc:`../cache/form_csrf_caching`.

.. todo link "only start a session when actually needed" to cookbook/session/avoid_session_start once https://github.com/symfony/symfony-docs/pull/4661 is merged
Cookies created in Javascript and used only in the frontend, e.g. when using
Google analytics are nonetheless sent to the server. These cookies are not
relevant for the backend and should not affect the caching decision. Configure
your Varnish cache to `clean the cookies header`_. You want to keep the
session cookie, if there is one, and get rid of all other cookies so that pages
are cached if there is no active session. Unless you changed the default
configuration of PHP, your session cookie has the name PHPSESSID:

.. code-block:: varnish4
sub vcl_recv {
// Remove all cookies except the session ID.
if (req.http.Cookie) {
set req.http.Cookie = ";" + req.http.Cookie;
set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");
set req.http.Cookie = regsuball(req.http.Cookie, ";(PHPSESSID)=", "; \1=");
set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");
if (req.http.Cookie == "") {
// If there are no more cookies, remove the header to get page cached.
remove req.http.Cookie;
}
}
}
.. tip::

If content is not different for every user, but depends on the roles of a
user, a solution is to separate the cache per group. This pattern is
implemented and explained by the FOSHttpCacheBundle_ under the name
`User Context`_.

Ensure Consistent Caching Behaviour
-----------------------------------

Expand Down Expand Up @@ -176,8 +227,10 @@ proxy before it has expired, it adds complexity to your caching setup.
.. _`Varnish`: https://www.varnish-cache.org
.. _`Edge Architecture`: http://www.w3.org/TR/edge-arch
.. _`GZIP and Varnish`: https://www.varnish-cache.org/docs/3.0/phk/gzip.html
.. _`Clean the cookies header`: https://www.varnish-cache.org/trac/wiki/VCLExampleRemovingSomeCookies
.. _`Surrogate-Capability Header`: http://www.w3.org/TR/edge-arch
.. _`cache invalidation`: http://tools.ietf.org/html/rfc2616#section-13.10
.. _`FOSHttpCacheBundle`: http://foshttpcachebundle.readthedocs.org/
.. _`default.vcl`: https://www.varnish-cache.org/trac/browser/bin/varnishd/default.vcl?rev=3.0
.. _`builtin.vcl`: https://www.varnish-cache.org/trac/browser/bin/varnishd/builtin.vcl?rev=4.0
.. _`User Context`: http://foshttpcachebundle.readthedocs.org/en/latest/features/user-context.html

0 comments on commit 87eb36c

Please sign in to comment.