1

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

我想这样做以测试OPCache 扩展的工作原理。

后期编辑:当 PHP 脚本加载时,代码被编译成字节码,这个字节码将被 CPU 解释。编译过程通常需要几毫秒,但我需要让这个时间非常长,以测试 PHP 5.5 的 OPCache 扩展。这个扩展应该缓存脚本字节码,这样它就不需要再次编译脚本。

4

1 回答 1

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
于 2014-10-04T19:40:39.737 回答