运行“;exec()";在“;windows+apache+php5.4”;比命令行慢


running "exec()" under "windows+apache+php5.4" slower than command line

由于某些原因,我需要在Windows+PHP中运行C++程序PHP类似代码:

$start = microtime();
exec("test.exe");
$end = microtime();

当我在命令行中以php test.php的形式运行这个php文件时,"test.exe"告诉它的开销时间是11秒。但我在类似localhost/test.php的浏览器中用apache运行了它,它最终输出了252秒。

当apache派生一个新进程或其他什么时,它有限制吗?


顺便说一句,"test.exe"是我为使用windbg分析数据而编写的一个程序。

我用一些数据来测试它的性能。

i。直接使用"test.exe"

CDumpAnalyze::Analyze time cost[2.328000]

ii。使用php命令行调用。

$start = microtime();
system("cd F:''DumpPlatform''bin''server && test.exe --cfg=dump_config.ini --gameversion=10000");
//exec("dir");
$end = microtime();
echo $start."'n";
echo $end."'n";
CDumpAnalyze::Analyze time cost[2.982000]
0.09448800 1378104101
0.11078900 1378104104

iii。使用apache 运行

CDumpAnalyze::Analyze time cost[63.158000] 
0.53862700 1378104642 
0.75394800 1378104705

显然,执行test.exe的时间成本没有差异。因此,差异与web服务器及其处理PHP脚本的方式有关。Apache是一个Thread Safe web服务器,为了管理其上的线程安全,存在许多调度表和其他进程表。此外,您的系统搜索从Apache exe文件到test.exe文件的路径所花费的时间可能会在超过您的时间成本方面发挥重要作用。

你可以在其他网络服务器上测试你的程序,并发布结果进行精确比较。