Administrators/Optimize performance/Webserver

From Aimeos documentation

Administrators | Optimize performance
Other languages:
English 100% • ‎русский 0%


Use PHP 7.0 or later

The core PHP developers improved the performance a lot in PHP 7.0 and later versions. You may see a speed increase of around 50% compared to PHP 5.6. Since PHP 5.5, a byte code cache is integrated, so this should be the minimum installed PHP version.

Even if PHP 5.5 implements a byte code cache, it doesn't contain a cache for storing configuration values and translated strings! Aimeos benefits a lot from caching this data and Aimeos is ca. 30% faster when using PHP with APCu.

Use APCu

Aimeos is a very powerful and flexible framework that is highly configurable and translated to many languages. Configuration and translations is stored in files by default which can cause a lot of disk reads per request. Installing the PHP APCu extension and configuring Aimeos to use it speeds up request times by ca. 30%. Make sure your APCu cache is bin enough for all configuration settings and translations that are used.

If the configuration values are cached within APCu, you have to clear this configuration cache (it's named "user" cache in APCu) each time you change a configuration value or translation. Otherwise, your application will behave not the way you expect.

Don't use open_basedir

If open_basedir is enabled, the PHP realpath cache is disabled for security reasons. This leads to a drastically reduced performance because Aimeos consists of a lot of files and for each file, a lstat() call is executed in each request. This can sum up to a few hundred times data is read from the hard disk and accessing the hard disk is extremely slow. You will even notice the slowdown on SSDs clearly.

The open_basedir feature is disabled by default. If it's enabled, you can disable it in your virtual host configuration by using:

php_admin_value open_basedir none

You can not disable open_basedir in your .htaccess file, only in your web server configuration!

The open_basedir feature is used by some admins to improve security but that approach is flawed! For a real separation you have to use operating features like chroot or jails.

Adapt PHP's realpath cache size

Aimeos consists of a lot of files and include_once will check some information for each included file via the lstat system call. On fast (local) file systems you won't notice that there are a lot of lstat calls because your hard disk is probably fast enough so they doesn't slow down the application.

Things are getting different with remote file systems like NFS. If you can't avoid using NFS, you can at least use PHP's realpath cache to reduce the number of lstat calls that have to be sent over the wire. There's an article with more details related to this problem available. The necessary settings for your host are:

php_admin_value realpath_cache_size 128K
php_admin_value realpath_cache_ttl 3600

A cache size of 128 KiB seems to be a good start as the Aimeos demo uses up to 80 KiB of the cache. You can check the actual yourself which is printed at end of the HTML source code for each request to the demo frontend. The value that fits best for you depends on the application which uses the Aimeos library. If the application also consists of a lot of files, you may need a higher value. To see the actually used cache, you can call a simple script from your browser that contains:

<?php echo realpath_cache_size();

James Hayden has written an article about how to optimize PHP's realpath cache size settings. As he states, the cache should be as big as necessary but as small as possible because the cache is per process. The TTL value (the time in seconds after which the file informations will be retrieved again from the file system) can be set to a high value if the permissions of the files doesn't change (which shouldn't be the case). The PHP documentation contains also a section about the realpath cache settings.

Don't store the source code on network shares

NFS (network file system) is a way to access files on a remote server over a network. It's great for sharing files between different hosts and is also sometimes used to provide a common installation for web applications. Nevertheless, it has one important drawback even if files are cached in the client cache: Often files have to be fetched from the remote server and compared to a local hard disc, this is painfully slow. Tests have shown that serving a request takes 3-4 times longer when the Aimeos files are located on a NFS server instead of a local hard disc.

If you have to use NFS for some reasons, the PHP OPcache can help to mitigate the problem a bit. Make sure your PHP installation uses this configuration:

php_admin_value opcache.revalidate_freq 0

This disables checking the modification time of each file and significantly improves performance on NFS shares by ca. 50%. See the PHP documentation for more information. Also be aware of the fact that you have to clear the OPcache before code changes will have any effect and you should activate this setting only on production servers where the code changes rarely.

Adapting PHP's realpath cache size can also help to reduce the performance loss on NFS.

Serve static content from caches

A web server needs much longer to serve static files than a caching proxy server like Squid. Files fitting into the main memory of the proxy server are sent to the clients almost instantly and the web server can concentrate on executing the PHP scripts that generate the HTML source code.

If your visitors are from differenct continents, you should think about using a content delivery network (CDN). The static files like images, CSS and JavaScript files can be served much faster by a cache that is geographically nearby the visitor because the latency for the requested files is small. The difference can be up to several seconds for the page load time.