Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if PHP JIT is enabled

Tags:

php

jit

php-8

What is the simplest way to detect if PHP is compiled with JIT and JIT is enabled from the running script?

like image 765
mvorisek Avatar asked Jun 30 '20 09:06

mvorisek


Video Answer


3 Answers

You can query the opcache settings directly by calling opcache_get_status():

opcache_get_status()["jit"]["enabled"];

or perform a lookup in the php.ini:

ini_get("opcache.jit")

which is an integer (returned as string) where the last digit states the status of the JIT:

0 - don't JIT
1 - minimal JIT (call standard VM handlers)
2 - selective VM handler inlining
3 - optimized JIT based on static type inference of individual function
4 - optimized JIT based on static type inference and call tree
5 - optimized JIT based on static type inference and inner procedure analyses

Source: https://wiki.php.net/rfc/jit#phpini_defaults

like image 59
maio290 Avatar answered Oct 11 '22 22:10

maio290


opcache_get_status() will not work when JIT is disabled and will throw Fatal error.

echo (function_exists('opcache_get_status') 
      && opcache_get_status()['jit']['enabled']) ? 'JIT enabled' : 'JIT disabled';

We must have following settings for JIT in php.ini file.

zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1 //optional, for CLI interpreter
opcache.jit_buffer_size=32M //default is 0, with value 0 JIT doesn't work
opcache.jit=1235 //optional, default is "tracing" which is equal to 1254
like image 25
Jsowa Avatar answered Oct 11 '22 23:10

Jsowa


php -i | grep "opcache"

checking:
opcache.enable => On => On
opcache.enable_cli => On => On
opcache.jit => tracing => tracing
like image 2
Leo Yuee Avatar answered Oct 11 '22 22:10

Leo Yuee