教你PHP8如何开启JIT

邓草 / 2024-10-19 / 原文

一,测试是否开启jit?

[liuhongdi@img ~]$ more jit.php
<?php
var_dump(opcache_get_status()['jit']);
?>

报错:

[liuhongdi@img ~]$ /usr/local/soft/php8.2.5/bin/php jit.php
PHP Fatal error:  Uncaught Error: Call to undefined function opcache_get_status() in /home/liuhongdi/jit.php:2
Stack trace:
#0 {main}
  thrown in /home/liuhongdi/jit.php on line 2

二,配置jit

[root@img etc]# vi php.ini

1,编辑内容:

在[opcache]一栏下增加四行

opcache.enable=1
opcache.enable_cli=1
opcache.jit_buffer_size=128M
opcache.jit=1255

2,Dynamic Extensions一栏下面:

把zend_extension=opcache一行取消注释

如下:

;zend_extension=opcache
zend_extension=opcache

三,测试效果:

[root@img etc]# /usr/local/soft/php8.2.5/bin/php /home/liuhongdi/jit.php
array(7) {
  ["enabled"]=>
  bool(true)
  ["on"]=>
  bool(true)
  ["kind"]=>
  int(5)
  ["opt_level"]=>
  int(5)
  ["opt_flags"]=>
  int(6)
  ["buffer_size"]=>
  int(134217712)
  ["buffer_free"]=>
  int(134215280)
}

如enabled和on两项的值为true,则表示jit已开启

四,查看php版本:

[liuhongdi@img ~]$ /usr/local/soft/php8.2.5/bin/php -v
PHP 8.2.5 (cli) (built: May 10 2023 14:51:39) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.5, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.5, Copyright (c), by Zend Technologies