JIT(Just-in-time) compilation is a process that takes compilation of the code at run time. JIT compilation allows to improve performance of interpreted programming languages.
Since PHP 8.0, we can use JIT. In order to use JIT the OPcache extension must be installed and enabled. OPcache extension allows to eliminate the need to load and parse scripts on every request by storing precompiled script bytecode in shared memory.
Enabling OPcache
The zend_extension directive can be used to load the OPcache extension into PHP. We can set zend_extension directive in php.ini file.
zend_extension=opcache
The opcache_get_status function can be used to check whether OPcache is enabled or not? Check with below code.
<?php function isOpcacheEnabled(): bool { if (!function_exists('opcache_get_status')) { return false; } return !empty(opcache_get_status()['opcache_enabled']); } echo isOpcacheEnabled() ? 'Enabled' : 'Disabled'; ?>
After OPcache have enabled we can start to configure JIT. The opcache.jit_buffer_size directive defines how much shared memory can be reserved for compiled JIT code. Value can be specified as integer in bytes or using shorthand notation with data size.
Default value is 0. This means that JIT is disabled.
opcache.jit_buffer_size=128M
To check whether JIT is enabled the opcache_get_status function can be used. Check with below code.
<?php function isJitEnabled(): bool { if (!function_exists('opcache_get_status')) { return false; } return !empty(opcache_get_status()['jit']['enabled']); } echo isJitEnabled() ? 'Enabled' : 'Disabled'; ?>
If you successfully enable JIT by using this post, make a comment please.
Thanks