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
测试

3、php8
测试

二、JIT
(即时编译)编译器
JIT
(Just-In-Time)即时编译器是 PHP 8.0
中最重要的新功能之一,可以极大地提高性能。JIT
编译器将作为扩展集成到 php
中 Opcache
扩展 用于运行时将某些操作码直接转换为从 cpu
指令。 仅在启用 opcache
的情况下,JIT
才有效
1、Opcache
扩展
OPcache
通过将 PHP
脚本预编译的字节码存储到共享内存中来提升 PHP
的性能, 存储预编译字节码的好处就是:省去了每次加载和解析 PHP
脚本的开销。
2、Opcache
开启
- 文件位置:softs\php\php-8.0.2-nts\php.ini
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
速度测试

6、php 扩展目录