Skip to content

Updated the article about performance tuning tips #6937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 18, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions performance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ application even faster.
.. index::
single: Performance; Byte code cache

Use a Byte Code Cache (e.g. APC)
--------------------------------
Use a Byte Code Cache (e.g. OPcache)
------------------------------------

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

Using a byte code cache really has no downside, and Symfony has been architected
to perform really well in this type of environment.
Expand All @@ -43,6 +43,25 @@ your ``php.ini`` configuration.
.. index::
single: Performance; Autoloader

Configure the PHP realpath cache
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cache

--------------------------------

PHP uses an internal cache to store the result of mapping file paths to their
real and absolute file system paths. This increases the performance for
applications like Symfony that open many PHP files, specially on Windows
systems.

By default PHP sets a default ``realpath_cache_size`` of ``16K`` which is too
low for Symfony. Consider updating this value at least to ``4096K``. In
addition, cached paths are only stored for ``120`` seconds. Consider updating
this value too using the ``realpath_cache_ttl`` option:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"[...] option in your php.ini file:"


.. code-block:: ini

; php.ini
realpath_cache_size=4096K
realpath_cache_ttl=600
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to indent with 4 spaces


Use Composer's Class Map Functionality
--------------------------------------

Expand All @@ -52,18 +71,25 @@ automatically find any new classes that you've placed in the registered
directories.

Unfortunately, this comes at a cost, as the loader iterates over all configured
namespaces to find a particular file, making ``file_exists`` calls until it
namespaces to find a particular file, making ``file_exists()`` calls until it
finally finds the file it's looking for.

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

The class map can be generated from the command line, and might become part of
your deploy process:

.. code-block:: bash

$ composer dump-autoload --optimize
$ composer dump-autoload --optimize --no-dev --classmap-authoritative

Internally, this builds the big class map array in ``vendor/composer/autoload_classmap.php``.
The ``--optimize`` option dumps every PSR-0 and PSR-4 compatible class used in
your application. The ``--no-dev`` option excludes the classes that are only
needed in the development environment (e.g. tests). The ``--classmap-authoritative``
option prevents Composer from scanning the file system for classes that are not
found in the class map.

Caching the Autoloader with APC
-------------------------------
Expand Down