如何检测PHP JIT是否启用

问题描述 投票:0回答:4

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

php jit php-8
4个回答
9
投票

您可以直接调用

opcache_get_status()
来查询opcache设置:

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


4
投票
php -i | grep "opcache"

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

3
投票

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

0
投票

如果您使用 WordPress,则可以使用 atec Cache Info 插件。

© www.soinside.com 2019 - 2024. All rights reserved.