• Welcome to Journal web site.

我是 PHP 程序员

- 开发无止境 -

Next
Prev

PHP8 新特性:JIT

Data: 2022-07-23 09:56:48Form: JournalClick: 0

# PHP8 新特性:JIT


# 一、PHP 运行速度测试

# 1、新建php文件

<?php
    // 返回当前时间戳的微秒数
    $start = microtime(true) ;

    $total = 0;
    for ($i=0; $i < 1000000; $i++) {
        $total += $i;
    }

    echo "Count: ".$i.",Total: " . $total . "\n";

    // 返回当前时间戳的微秒数
    $end = microtime(true);

    // 计算开始到结束,所用时间
    $spend = floor(($end - $start) * 1000);

    echo "Time use: " . $spend . " ms\n";
?>

# 2、php7 测试

php8

# 3、php8 测试

php8


# 二、JIT (即时编译)编译器

  • JIT (Just-In-Time)即时编译器是 PHP 8.0 中最重要的新功能之一,可以极大地提高性能。
  • JIT 编译器将作为扩展集成到 phpOpcache 扩展 用于运行时将某些操作码直接转换为从 cpu 指令。 仅在启用 opcache 的情况下,JIT 才有效

# 1、Opcache 扩展

  • OPcache 通过将 PHP 脚本预编译的字节码存储到共享内存中来提升 PHP 的性能, 存储预编译字节码的好处就是:省去了每次加载和解析 PHP 脚本的开销。

# 2、Opcache 开启

  • 文件位置:softs\php\php-8.0.2-nts\php.ini
zend_extension=opcache

# 3、Opcache 配置

; Determines if Zend OPCache is enabled
opcache.enable=1

; Determines if Zend OPCache is enabled for the CLI version of PHP
opcache.enable_cli=0

; The OPcache shared memory storage size.
opcache.memory_consumption=128

; The amount of memory for interned strings in Mbytes.
opcache.interned_strings_buffer=8

; The maximum number of keys (scripts) in the OPcache hash table.
; Only numbers between 200 and 1000000 are allowed.
opcache.max_accelerated_files=10000

# 4、JIT 配置(新增)

opcache.jit=tracing
opcache.jit_buffer_size=100M

# 5、JIT 速度测试

php8

# 6、php 扩展目录

extension_dir = "ext"
Name:
<提交>