1st level cache
To be installed on the server, to compress PHP functions / code:
xCache < PHP 5.6
opCache > PHP 7+
Tools for dimensionning idealy the configuration: opCache GUI (make sure all the pages were previously accessed to be sure all the code is cached, before optimising anything).
Important: for a live installation, disable the Timestamp based renewal of cache.
Any further PHP file modification will not be taken unless the cache system is cleared.
OPCache
This cache puts PHP code in cache, therefore increasing the speed of treatment for all PHP code.
It is a server side Cache, and unlike Litespeed or standard CMS caches which work on HTML/CSS (client vue), it works on server side code.
Any website using PHP can use this Cache. And it will work with a standard cache, as they dont work on the same files !
To enable it: just need to enable the "op_cache" extension on the server (PHP plugins)
To measure it: 2 files are there in OneDrive in /Tools/OPCache/:
opcache.php: to see the cache infos
flush_cache.php: to clear the cache
We can put those files in a /cache/ folder or in root of our projects.
2 important informations:
- need to check the Memory, it has to be enough. If not enough, need to inscrease allocated memory in PHP options > OP Cache (
opcache.memory_consumption) - need to disable automatic deletion of cache from PHP options > OP Cache when site is live (
opcache.validate_timestamps=> 0)
Then just need to remember that after any modification in PHP code, need to clear this cache as well using the flush_cache file.
Information about the values to set:
opcache.memory_consumption: Defines the shared memory storage used by OPcache (in megabytes). A value of 128 is a solid default for standard or medium-sized PHP projects. If your site handles a large volume of traffic (e.g., WooCommerce) or has a large footprint, you can increase this to 256.
opcache.max_accelerated_files: Dictates the maximum number of PHP files that can be cached. Ensure this number is larger than the total number of PHP files in your project (you can check this with find . -iname "*.php" | wc -l). 10000 or 16229 are safe, standard choices for modern frameworks like WordPress or Laravel.
opcache.interned_strings_buffer: Memory allocated for storing interned strings in megabytes. 16 generally performs well.
opcache.revalidate_freq: Frequency (in seconds) that OPcache checks for updated PHP file timestamps. For production environments, 60 is ideal to balance performance and file updates. For development environments, you may want to set this to 0 so changes take effect immediately.
opcache.validate_timestamps: When enabled, OPcache will check file modification timestamps per your revalidate_freq. On production, set to 1 so updates to your site files eventually reflect.
2nd level cache
Can be installed additionnally, to add a global cache on upper levels / layers of a web application.
Memcached => key/value cache, for a quick access to a compressed content (small blocks and queries).
In PrestaShop, with Planethoster, here are the values to give to configure it:
IP address: /home/USERN0C/.memcached/memcached.sock
port: 0
weight: 1
Litespeed => cache on HTTP requests, for full pages caching
Most Commented