Image

Knowledge base → Increasing website speed using php 8 settings

[Virtual servers] [Applications on VPS/VDS]
Date of publication: 26.03.2024

PHP 8 has new features for optimizing performance and a new feature that increases the speed of scripts called JIT (Just In Time) compilation.

Pure interpreted programming languages have no compilation step and directly execute code on the virtual machine. Most interpreted languages, including PHP, actually have a lightweight compilation step to improve performance.

On the other hand, ahead-of-time (AOT) programming languages require the code to be compiled before it can be run.

Just In Time (JIT) compilation is a hybrid model of interpreter and ahead-of-time compilation in which some or all of the code is compiled, often at runtime, without the need for the developer to compile it manually.

This option is controlled in the opcache module. This module is designed to speed up the operation of scripts, and enabling JIT further speeds up the execution of scripts - i.e. allows for double acceleration.

Comparative speed increase graph.

In our example we will use php 8.3.

1. Check for module availability

php8.3 -m | grep OPcache

In the output, it may appear 2 times in the general section and the Zend modules section. This means it is enabled.

1.1 If it is turned off, turn it on

In our example, we use Debian 12 and your paths may differ.

nano /etc/php/8.3/fpm/conf.d/10-opcache.ini
; configuration for php opcache module
; priority=10
opcache.enable=1
opcache.revalidate_freq=0
opcache.validate_timestamps=1
opcache.max_accelerated_files=10000
opcache.memory_consumption=192
opcache.max_wasted_percentage=10
opcache.interned_strings_buffer=16
opcache.fast_shutdown=1
zend_extension=opcache.so
opcache.jit=on

1.2 Enable the module in php settings

nano /etc/php/8.3/fpm/php.ini

Add to the very end of the configuration line:

zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1
opcache.jit_buffer_size=256M
opcache.jit=1235

1.3 Restart fpm

service php8.3-fpm restart
service php8.3-fpm status

1.4 Let's check the presence of the module again

php8.3 -m | grep OPcache

1.5 Checking with a script

Let's create a php file with the following contents

touch info.php
nano info.php
<?php
phpinfo();
?>

Open the script through the browser http[s]://domain.tld/info.php and using the Ctrl + f search for the word opcache, find the settings parameters.

These lines indicate that the OPcache module and the JIT add-on are enabled.





No Comments Yet