如何检测是否启用了PHP JIT

如何检测是否启用了PHP JIT,php,jit,php-8,Php,Jit,Php 8,检测PHP是否使用JIT编译以及是否从运行的脚本启用JIT的最简单方法是什么?您可以通过调用以下命令直接查询opcache设置: 或者在php.ini中执行查找: ini_get("opcache.jit") 这是一个整数(返回为字符串),其中最后一位数字表示JIT的状态: 0 - don't JIT 1 - minimal JIT (call standard VM handlers) 2 - selective VM handler inlining 3 - optim

检测PHP是否使用JIT编译以及是否从运行的脚本启用JIT的最简单方法是什么?

您可以通过调用以下命令直接查询opcache设置:

或者在
php.ini
中执行查找:

ini_get("opcache.jit")
这是一个整数(返回为字符串),其中最后一位数字表示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
来源:

opcache\u get\u status()
在禁用JIT时将不工作,并将引发致命错误

echo (function_exists('opcache_get_status') 
      && opcache_get_status()['jit']['enabled']) ? 'JIT enabled' : 'JIT disabled';
我们必须在
php.ini
文件中对JIT进行以下设置

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

因此,您需要一种方法来检查脚本是否已编译或解释?理想情况下两者都有,但至少在解释时是这样。它似乎不起作用-
var_dump(ini_get(“opcache.jit”)返回带JIT和不带JIT的
字符串(4)“1205”
,使用@mvorisek测试,我已更新了答案。我猜opcache_get_status()函数正是您想要的。谢谢,下面的工作:
opcache_get_status()[“jit”][“enabled”]??false
请更新您的答案,并提供有关您的代码的详细信息,以及它如何回答问题。
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
php -i | grep "opcache"

checking:
opcache.enable => On => On
opcache.enable_cli => On => On
opcache.jit => tracing => tracing