Please enable JavaScript to view this site.
PHP has a caching system called OPcache. Here's a little bit of background.
PHP translates human-readable code to machine code through interpretation (aka Implicit Compilation). The interpreted code is known as OPcode and is compiled and executed by the Zend Virtual Machine. Other methods of translating human-readable code are Ahead Of Time (AOT) compilation and Just In Time (JIT) compilation.
The stored OPcode is called the OPcache. OPcache resides in RAM memory and improves PHP performance because PHP no longer needs to load and parse scripts on each request. Instead, the PHP and the Zend Virtual Machine use the OPcache, which has already been loaded and parsed.
OPCaching is turned on by default in PHP.
PHP 8 offers a new hybrid method of compiling code that complements the Zend Virtual Machine with Just In Time compilation. PHP algorithms decide when JIT compilation should skip Zend Virtual Machine code execution and, instead, translate OPcode directly into machine code. JIT can speed up PHP's performance.
In addition, the OPcache can be can be backed up by a file disk caching feature. The main OPcache resides in RAM, while OPcode backup files are stored on disk. The OPcache code stored in RAM memory allows for fast execution, but if the RAM memory is flushed, the system can use the OPcode stored in disk files for backup processing.
The following steps show how to enable JIT and OPcode disk file backup caching.
First create a folder for the OPcode disk file cache. Preferably, the folder should be outside the document root. For this example, the folder will be located at
Create the folder and assign www-data as the owner:
Find the location of the opcache.ini file:
Edit opache.ini file:
Insert the following code in the opcache.ini file:
Check if opcache is enabled (command line):
Check if JIT is enabled (command line):
If all is good, reboot for JIT and OP file caching to become activated.
For more information, see thePHP Website and PHP Opcache file cache.
PHP translates human-readable code to machine code through interpretation (aka Implicit Compilation). The interpreted code is known as OPcode and is compiled and executed by the Zend Virtual Machine. Other methods of translating human-readable code are Ahead Of Time (AOT) compilation and Just In Time (JIT) compilation.
The stored OPcode is called the OPcache. OPcache resides in RAM memory and improves PHP performance because PHP no longer needs to load and parse scripts on each request. Instead, the PHP and the Zend Virtual Machine use the OPcache, which has already been loaded and parsed.
OPCaching is turned on by default in PHP.
PHP 8 offers a new hybrid method of compiling code that complements the Zend Virtual Machine with Just In Time compilation. PHP algorithms decide when JIT compilation should skip Zend Virtual Machine code execution and, instead, translate OPcode directly into machine code. JIT can speed up PHP's performance.
In addition, the OPcache can be can be backed up by a file disk caching feature. The main OPcache resides in RAM, while OPcode backup files are stored on disk. The OPcache code stored in RAM memory allows for fast execution, but if the RAM memory is flushed, the system can use the OPcode stored in disk files for backup processing.
The following steps show how to enable JIT and OPcode disk file backup caching.
First create a folder for the OPcode disk file cache. Preferably, the folder should be outside the document root. For this example, the folder will be located at
/var/www/opcache.
Create the folder and assign www-data as the owner:
sudo mkdir /var/www/opcache
sudo chown www-data:www-data /var/www/opcache
Find the location of the opcache.ini file:
php -i | grep opcache.ini
Edit opache.ini file:
sudo nano /etc/php/8.3/cli/conf.d/10-opcache.ini
Insert the following code in the opcache.ini file:
; configuration for php opcache moduleCheck for errors (command line):
; priority=10
zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1
opcache.jit_buffer_size=100M
opcache.jit=1255
php -i | grep opcache.iniphp -i | grep opcache.ini
Check if opcache is enabled (command line):
php -i | grep 'opcache.enable'
Check if JIT is enabled (command line):
php -i | grep -E '^opcache.(enable_cli|jit|jit_buffer_size)'
If all is good, reboot for JIT and OP file caching to become activated.
For more information, see thePHP Website and PHP Opcache file cache.
* posted by Robert on Wed, May 15, 2024
Site built and hosted by RJdesign.one