3

出于某种原因,我需要在Windows + PHP中运行C++程序。PHP代码如:

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

当我php test.php在命令行中运行这个 php 文件时,“test.exe”告诉它的成本时间是 11 秒。但我在浏览器中使用 apache 运行它localhost/test.php,最终输出它花费了 252 秒。

当它派生一个新进程或其他东西时,它是否有任何限制?


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

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

一世。直接使用“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. 用阿帕奇运行

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

1 回答 1

0

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

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

于 2013-09-07T11:28:01.557 回答