如何检测是否启用了PHP JIT

时间:2020-06-30 09:32:17

标签: php jit php-8

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

3 个答案:

答案 0 :(得分:4)

您可以通过调用opcache_get_status()直接查询操作缓存设置:

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

或在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

来源:https://wiki.php.net/rfc/jit#phpini_defaults

答案 1 :(得分:1)

opcache_get_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

答案 2 :(得分:1)

php -i | grep "opcache"

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