Laravel/Optimize performance

From Aimeos documentation

Laravel
Other languages:
English 100%

Enable APC

A big performance boost can be achieved by installing APCu (the APC user cache). It can cache all configuration and translation entries in the shared memory of the web server which can improve performance by 50%.

Be aware that you have to clear the APC user cache manually each time after you've changed a configuration option or a translation!

In order to tell your application to use the APC user cache, you need to change the apc_enabled setting in the ./config/shop.php file of your application:

  1. return array(
  2.     'apc_enabled' => true,
  3.     'apc_prefix' => 'laravel:',
  4.     // ....
  5. );

If you have more than one shop application on the same server, you must assign an unique apc_prefix for each instance! More about APC can be found in the administrator section.

Cache component content

The content cache is usually enabled by default if you haven't disabled it during development in your ./config/shop.php:

classes/cache/manager/name => 'None'

If you have a high volume of products (50k+) and your database server gets slower due to the amount of queries executed, you can offload the content cache entries either to another database server or to an in-memory key/value store like Redis.

To move the content cache entries to a Redis server, you have to install the ai-cache extension. The extension contains documentation how to configure your application for Redis support.

Alternatively, you can move the cached component content to another database server. In this case, you must add a db-cache resource block to your ./config/shop.php:

  1. return array(
  2.     // ..
  3.     'resource' => array(
  4.         // ..
  5.         'db-cache' => array(
  6.             'adapter' => 'mysql',
  7.             'host' => '...',
  8.             'port' => '...',
  9.             'database' => '...',
  10.             'username' => '...',
  11.             'password' => '...',
  12.             'stmt' => array( "SET NAMES 'utf8'", "SET SESSION sql_mode='ANSI'" ),
  13.             'opt-persistent' => 0,
  14.             'limit' => 2,
  15.         ),
  16.     ),
  17.     // ...
  18. );

You can even distribute the Aimeos database to serveral database servers. More information is available in the developer section.

Use a different domain for static files

Browsers don't load all required files at once referenced inside a HTML document. Instead, they limit the number of concurrent requests for a single domain. To get around this, a common way is to make the files also available via a different domain, so the browsers will download more files in parallel. Thus, rendering the page is much faster for the user.

  • One way is to create a second virtual host configuration in your web server which uses a sub-domain like "static.example.com". The document root should point to the same directory as your main virtual host (e.g. example.com) in the file system to ease maintenance. Otherwise you would have to make sure that the files are in sync in both directories. If the internet connection to your customers is short and fast and your server is able to handle the load, this way is the preferred one - especially, if you are able to serve the files from a memory-based cache like Squid or Varnish.
  • Another option is to use a domain from a content delivery network (CDN) like Amazon Cloudfront. Usually, you can configure these services to retrieve the static files on the first request from your host and deliver them from their caches afterwards. The advantage of a CDN over a sub-domain on your own server is the load-balancing across many servers and the distribution from a server near to the visitors of your web site. Both can improve the speed of your web site a lot.

In both cases, you need to configure the Aimeos Laravel package to create links to the product pictures with a different domain. This can be done via an entry in the config/shop.php file:

  1. 'client' => array(
  2.     'html' => array(
  3.         'common' => array(
  4.             'content' => array(
  5.                 'baseurl' => 'https://static.example.com/media/',
  6.             ),
  7.         ),
  8.     ),
  9. ),