Skip to content

Commit 87eb36c

Browse files
committed
Merge branch '2.7'
2 parents 714f630 + bc29584 commit 87eb36c

File tree

5 files changed

+59
-4
lines changed

5 files changed

+59
-4
lines changed

book/forms.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ That's it! Just three lines are needed to render the complete form:
175175
Renders all the fields, which includes the field element itself, a label
176176
and any validation error messages for the field.
177177

178-
``form_end()``
178+
``form_end(form)``
179179
Renders the end tag of the form and any fields that have not
180180
yet been rendered, in case you rendered each field yourself. This is useful
181181
for rendering hidden fields and taking advantage of the automatic

book/http_cache.rst

+2
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@ This has two very reasonable consequences:
383383
blog post). Caching them would prevent certain requests from hitting and
384384
mutating your application.
385385

386+
.. _http-cache-defaults:
387+
386388
Caching Rules and Defaults
387389
~~~~~~~~~~~~~~~~~~~~~~~~~~
388390

book/internals.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ The FrameworkBundle registers several listeners:
375375

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

378-
The purpose of this event is to to handle tasks that should be performed after
378+
The purpose of this event is to handle tasks that should be performed after
379379
the request has been handled but that do not need to modify the response.
380380
Event listeners for the ``kernel.finish_request`` event are called in both
381381
successful and exception cases.

components/filesystem/introduction.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ endpoint for filesystem operations::
3131
$fs = new Filesystem();
3232

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

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

5858
$fs->mkdir('/tmp/photos', 0700);

cookbook/cache/varnish.rst

+53
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,57 @@ If the ``X-Forwarded-Port`` header is not set correctly, Symfony will append
6060
the port where the PHP application is running when generating absolute URLs,
6161
e.g. ``http://example.com:8080/my/path``.
6262

63+
Cookies and Caching
64+
-------------------
65+
66+
By default, a sane caching proxy does not cache anything when a request is sent
67+
with :ref:`cookies or a basic authentication header<http-cache-introduction>`.
68+
This is because the content of the page is supposed to depend on the cookie
69+
value or authentication header.
70+
71+
If you know for sure that the backend never uses sessions or basic
72+
authentication, have varnish remove the corresponding header from requests to
73+
prevent clients from bypassing the cache. In practice, you will need sessions
74+
at least for some parts of the site, e.g. when using forms with
75+
:ref:`CSRF Protection <forms-csrf>`. In this situation, make sure to only
76+
start a session when actually needed, and clear the session when it is no
77+
longer needed. Alternatively, you can look into :doc:`../cache/form_csrf_caching`.
78+
79+
.. 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
80+
81+
Cookies created in Javascript and used only in the frontend, e.g. when using
82+
Google analytics are nonetheless sent to the server. These cookies are not
83+
relevant for the backend and should not affect the caching decision. Configure
84+
your Varnish cache to `clean the cookies header`_. You want to keep the
85+
session cookie, if there is one, and get rid of all other cookies so that pages
86+
are cached if there is no active session. Unless you changed the default
87+
configuration of PHP, your session cookie has the name PHPSESSID:
88+
89+
.. code-block:: varnish4
90+
91+
sub vcl_recv {
92+
// Remove all cookies except the session ID.
93+
if (req.http.Cookie) {
94+
set req.http.Cookie = ";" + req.http.Cookie;
95+
set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");
96+
set req.http.Cookie = regsuball(req.http.Cookie, ";(PHPSESSID)=", "; \1=");
97+
set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
98+
set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");
99+
100+
if (req.http.Cookie == "") {
101+
// If there are no more cookies, remove the header to get page cached.
102+
remove req.http.Cookie;
103+
}
104+
}
105+
}
106+
107+
.. tip::
108+
109+
If content is not different for every user, but depends on the roles of a
110+
user, a solution is to separate the cache per group. This pattern is
111+
implemented and explained by the FOSHttpCacheBundle_ under the name
112+
`User Context`_.
113+
63114
Ensure Consistent Caching Behaviour
64115
-----------------------------------
65116

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

0 commit comments

Comments
 (0)