@@ -6,44 +6,48 @@ Performance
6
6
7
7
Symfony is fast, right out of the box. Of course, if you really need speed,
8
8
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.
11
10
12
11
.. index ::
13
12
single: Performance; Byte code cache
14
13
15
14
Use a Byte Code Cache (e.g. OPcache)
16
15
------------------------------------
17
16
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 `APC `_.
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.
20
+
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 `_.
24
24
25
25
Using a byte code cache really has no downside, and Symfony has been architected
26
26
to perform really well in this type of environment.
27
27
28
28
Further Optimizations
29
29
~~~~~~~~~~~~~~~~~~~~~
30
30
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.
34
34
35
35
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.
39
42
40
- For example, to disable these checks in APC, simply add ``apc.stat=0 `` to
41
- your ``php.ini `` configuration.
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).
42
46
43
47
.. index ::
44
48
single: Performance; Autoloader
45
49
46
- Configure the PHP realpath cache
50
+ Configure the PHP realpath Cache
47
51
--------------------------------
48
52
49
53
PHP uses an internal cache to store the result of mapping file paths to their
@@ -54,7 +58,7 @@ systems.
54
58
By default PHP sets a ``realpath_cache_size `` of ``16K `` which is too low for
55
59
Symfony. Consider updating this value at least to ``4096K ``. In addition, cached
56
60
paths are only stored for ``120 `` seconds by default. Consider updating this
57
- value too using the ``realpath_cache_ttl `` option in your `` php.ini `` file :
61
+ value too using the ``realpath_cache_ttl `` option:
58
62
59
63
.. code-block :: ini
60
64
@@ -85,11 +89,14 @@ your deploy process:
85
89
86
90
$ composer dump-autoload --optimize --no-dev --classmap-authoritative
87
91
88
- The ``--optimize `` option dumps every PSR-0 and PSR-4 compatible class used in
89
- your application. The ``--no-dev `` option excludes the classes that are only
90
- needed in the development environment (e.g. tests). The ``--classmap-authoritative ``
91
- option prevents Composer from scanning the file system for classes that are not
92
- found in the class map.
92
+ ``--optimize ``
93
+ Dumps every PSR-0 and PSR-4 compatible class used in your application.
94
+ ``--no-dev ``
95
+ Excludes the classes that are only needed in the development environment
96
+ (e.g. tests).
97
+ ``--classmap-authoritative ``
98
+ Prevents Composer from scanning the file system for classes that are not
99
+ found in the class map.
93
100
94
101
Caching the Autoloader with APC
95
102
-------------------------------
0 commit comments