如何在PHP中获得更长的编译时间

时间:2014-10-04 18:36:30

标签: php opcache

我想知道如何编写需要更长编译时间的PHP脚本?

我想在OPCache扩展程序中执行此操作测试

稍后编辑: 加载PHP脚本时,代码将编译为字节码,此字节码将由CPU解释。编译过程通常需要几毫秒,但我需要花费这么多时间来测试PHP 5.5的OPCache扩展。此扩展应该缓存脚本字节码,以便它不再需要再次编译脚本。

1 个答案:

答案 0 :(得分:1)

正如@PaulCrovella在评论中所说,我需要的是ApacheBench。

在脚本上使用命令ab http://localhost/index.php,代码大约为600.000行,结果如下:

在第一次基准测试中:

Server Software:        Apache/2.4.9
Server Hostname:        localhost
Server Port:            80

Document Path:          /index.php
Document Length:        4927 bytes

Concurrency Level:      1
Time taken for tests:   0.944 seconds
Complete requests:      1
Failed requests:        0
Total transferred:      5116 bytes
HTML transferred:       4927 bytes
Requests per second:    1.06 [#/sec] (mean)
Time per request:       944.054 [ms] (mean)
Time per request:       944.054 [ms] (mean, across all concurrent requests)
Transfer rate:          5.29 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:   944  944   0.0    944     944
Waiting:      939  939   0.0    939     939
Total:        944  944   0.0    944     944

在第二次基准测试中:

Server Software:        Apache/2.4.9
Server Hostname:        localhost
Server Port:            80

Document Path:          /index.php
Document Length:        4927 bytes

Concurrency Level:      1
Time taken for tests:   0.047 seconds
Complete requests:      1
Failed requests:        0
Total transferred:      5116 bytes
HTML transferred:       4927 bytes
Requests per second:    21.28 [#/sec] (mean)
Time per request:       47.003 [ms] (mean)
Time per request:       47.003 [ms] (mean, across all concurrent requests)
Transfer rate:          106.29 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:    47   47   0.0     47      47
Waiting:       43   43   0.0     43      43
Total:         47   47   0.0     47      47