如何检测是否启用了 PHP JIT

Mvo*_*sek 11 php jit php-8

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

mai*_*290 6

您可以通过调用直接查询 opcache 设置opcache_get_status()

opcache_get_status()["jit"]["enabled"];
Run Code Online (Sandbox Code Playgroud)

或在以下位置执行查找php.ini

ini_get("opcache.jit")
Run Code Online (Sandbox Code Playgroud)

这是一个整数(作为字符串返回),其中最后一位数字表示 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
Run Code Online (Sandbox Code Playgroud)

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