Skip to content

Commit 9b1e819

Browse files
committed
Merge branch '3.1' into 3.2
* 3.1: [#6937] A few small tweaks! Porting #6937 back to 2.7 Remove yourself word in acl doc page %kernel.root_dir%/app/data/data.sqlite -> %kernel.root_dir%/data/data.sqlite Fix sample sqlite database path in doctrine config Fix sample sqlite database path in doctrine config Fixed code example wrong prepend() method declaration
2 parents 58b95bd + 47027c8 commit 9b1e819

File tree

3 files changed

+84
-30
lines changed

3 files changed

+84
-30
lines changed

performance.rst

Lines changed: 80 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,82 @@ Performance
66

77
Symfony is fast, right out of the box. Of course, if you really need speed,
88
there are many ways that you can make Symfony even faster. In this chapter,
9-
you'll explore many of the most common and powerful ways to make your Symfony
10-
application even faster.
9+
you'll explore some of the ways to make your Symfony application even faster.
1110

1211
.. index::
1312
single: Performance; Byte code cache
1413

15-
Use a Byte Code Cache (e.g. APC)
16-
--------------------------------
14+
Use a Byte Code Cache (e.g. OPcache)
15+
------------------------------------
16+
17+
The first thing that you should do to improve your performance is to use a
18+
"byte code cache". These caches store the compiled PHP files to avoid having
19+
to recompile them for every request.
1720

18-
One of the best (and easiest) things that you should do to improve your performance
19-
is to use a "byte code cache". The idea of a byte code cache is to remove
20-
the need to constantly recompile the PHP source code. There are a number of
21-
`byte code caches`_ available, some of which are open source. As of PHP 5.5,
22-
PHP comes with `OPcache`_ built-in. For older versions, the most widely used
23-
byte code cache is probably `APC`_
21+
There are a number of `byte code caches`_ available, some of which are open
22+
source. As of PHP 5.5, PHP comes with `OPcache`_ built-in. For older versions,
23+
the most widely used byte code cache is `APC`_.
2424

2525
Using a byte code cache really has no downside, and Symfony has been architected
2626
to perform really well in this type of environment.
2727

28-
Further Optimizations
29-
~~~~~~~~~~~~~~~~~~~~~
28+
Monitoring Source File Changes
29+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3030

31-
Byte code caches usually monitor the source files for changes. This ensures
32-
that if the source of a file changes, the byte code is recompiled automatically.
33-
This is really convenient, but obviously adds overhead.
31+
Most byte code caches monitor the source files for changes. This ensures that if
32+
the source of a file changes, the byte code is recompiled automatically.
33+
This is really convenient, but it adds overhead.
3434

3535
For this reason, some byte code caches offer an option to disable these checks.
36-
Obviously, when disabling these checks, it will be up to the server admin
37-
to ensure that the cache is cleared whenever any source files change. Otherwise,
38-
the updates you've made won't be seen.
36+
For example, to disable these checks in APC, simply add ``apc.stat=0`` to your
37+
``php.ini`` configuration.
38+
39+
When disabling these checks, it will be up to the server administrators to
40+
ensure that the cache is cleared whenever any source files change. Otherwise,
41+
the updates you've made in the application won't be seen.
42+
43+
For the same reasons, the byte code cache must also be cleared when deploying
44+
the application (for example by calling ``apc_clear_cache()`` PHP function when
45+
using APC and ``opcache_reset()`` when using OPcache).
46+
47+
.. note::
48+
49+
In PHP, the CLI and the web processes don't share the same OPcache. This
50+
means that you cannot clear the web server OPcache by executing some command
51+
in your terminal. You either need to restart the web server or call the
52+
``apc_clear_cache()`` or ``opcache_reset()`` functions via the web server
53+
(i.e. by having these in a script that you execute over the web).
54+
55+
Optimizing all the Files Used by Symfony
56+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57+
58+
By default, PHP's OPcache saves up to 2,000 files in the byte code cache. This
59+
number is too low for the typical Symfony application, so you should set a
60+
higher limit with the `opcache.max_accelerated_files`_ configuration option:
3961

40-
For example, to disable these checks in APC, simply add ``apc.stat=0`` to
41-
your ``php.ini`` configuration.
62+
.. code-block:: ini
63+
64+
; php.ini
65+
opcache.max_accelerated_files = 20000
66+
67+
Configure the PHP realpath Cache
68+
--------------------------------
69+
70+
PHP uses an internal cache to store the result of mapping file paths to their
71+
real and absolute file system paths. This increases the performance for
72+
applications like Symfony that open many PHP files, especially on Windows
73+
systems.
74+
75+
By default PHP sets a ``realpath_cache_size`` of ``16K`` which is too low for
76+
Symfony. Consider updating this value at least to ``4096K``. In addition, cached
77+
paths are only stored for ``120`` seconds by default. Consider updating this
78+
value too using the ``realpath_cache_ttl`` option:
79+
80+
.. code-block:: ini
81+
82+
; php.ini
83+
realpath_cache_size=4096K
84+
realpath_cache_ttl=600
4285
4386
.. index::
4487
single: Performance; Autoloader
@@ -55,15 +98,25 @@ Unfortunately, this comes at a cost, as the loader iterates over all configured
5598
namespaces to find a particular file, making ``file_exists()`` calls until it
5699
finally finds the file it's looking for.
57100

58-
The simplest solution is to tell Composer to build a "class map" (i.e. a
59-
big array of the locations of all the classes). This can be done from the
60-
command line, and might become part of your deploy process:
101+
The simplest solution is to tell Composer to build an optimized "class map",
102+
which is a big array of the locations of all the classes and it's stored
103+
in ``vendor/composer/autoload_classmap.php``.
104+
105+
The class map can be generated from the command line, and might become part of
106+
your deploy process:
61107

62-
.. code-block:: terminal
108+
.. code-block:: bash
63109
64-
$ composer dump-autoload --optimize
110+
$ composer dump-autoload --optimize --no-dev --classmap-authoritative
65111
66-
Internally, this builds the big class map array in ``vendor/composer/autoload_classmap.php``.
112+
``--optimize``
113+
Dumps every PSR-0 and PSR-4 compatible class used in your application.
114+
``--no-dev``
115+
Excludes the classes that are only needed in the development environment
116+
(e.g. tests).
117+
``--classmap-authoritative``
118+
Prevents Composer from scanning the file system for classes that are not
119+
found in the class map.
67120

68121
Caching the Autoloader with APC
69122
-------------------------------
@@ -147,6 +200,7 @@ Learn more
147200

148201
.. _`byte code caches`: https://en.wikipedia.org/wiki/List_of_PHP_accelerators
149202
.. _`OPcache`: http://php.net/manual/en/book.opcache.php
203+
.. _`opcache.max_accelerated_files`: http://php.net/manual/en/opcache.configuration.php#ini.opcache.max-accelerated-files
150204
.. _`APC`: http://php.net/manual/en/book.apc.php
151205
.. _`autoload.php`: https://github.com/symfony/symfony-standard/blob/master/app/autoload.php
152206
.. _`bootstrap file`: https://github.com/sensiolabs/SensioDistributionBundle/blob/master/Composer/ScriptHandler.php

reference/configuration/doctrine.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ Full Default Configuration
203203
password="secret"
204204
driver="pdo_mysql"
205205
driver-class="MyNamespace\MyDriverImpl"
206-
path="%kernel.data_dir%/data.sqlite"
206+
path="%kernel.root_dir%/../var/data/data.sqlite"
207207
memory="true"
208208
unix-socket="/tmp/mysql.sock"
209209
wrapper-class="MyDoctrineDbalConnectionWrapper"
@@ -395,7 +395,7 @@ The following block shows all possible configuration keys:
395395
# the DBAL driverOptions option
396396
options:
397397
foo: bar
398-
path: '%kernel.data_dir%/data.sqlite'
398+
path: '%kernel.root_dir%/data/data.sqlite'
399399
memory: true
400400
unix_socket: /tmp/mysql.sock
401401
# the DBAL wrapperClass option
@@ -431,7 +431,7 @@ The following block shows all possible configuration keys:
431431
password="secret"
432432
driver="pdo_mysql"
433433
driver-class="MyNamespace\MyDriverImpl"
434-
path="%kernel.data_dir%/data.sqlite"
434+
path="%kernel.root_dir%/../var/data/data.sqlite"
435435
memory="true"
436436
unix-socket="/tmp/mysql.sock"
437437
wrapper-class="MyDoctrineDbalConnectionWrapper"

security/acl.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ the ACL system comes in.
2222

2323
Imagine you are designing a blog system where your users can comment on your
2424
posts. Now, you want a user to be able to edit their own comments, but not those
25-
of other users; besides, you yourself want to be able to edit all comments. In
25+
of other users; besides, you want to be able to edit all comments. In
2626
this scenario, ``Comment`` would be the domain object that you want to
2727
restrict access to. You could take several approaches to accomplish this using
2828
Symfony, two basic approaches are (non-exhaustive):

0 commit comments

Comments
 (0)