简体   繁体   English

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

[英]running “exec()” under “windows+apache+php5.4” slower than command line

For some reason I need to run a C++ program in Windows + PHP . 出于某种原因,我需要在Windows + PHP中运行C ++程序。 PHP code like: PHP代码如:

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

When I ran this php file as php test.php in command line, "test.exe" told its cost time is 11s. 当我在命令行中将这个php文件作为php test.php运行时,“test.exe”告诉它的成本时间是11秒。 But I ran it with apache in browser like localhost/test.php , it finally output it costed 252s. 但我在浏览器中使用apache运行它,如localhost/test.php ,它最终输出成本为252s。

Is it any limit in apache when it fork a new process, or something else? 在分叉新进程或其他什么时,apache是​​否有任何限制?


btw, "test.exe" is a program that I wrote to analyze data with windbg. 顺便说一下,“test.exe”是我写的用windbg分析数据的程序。

I use a few data to test its performance. 我使用一些数据来测试它的性能。

i. 一世。 directly use "test.exe" 直接使用“test.exe”

CDumpAnalyze::Analyze time cost[2.328000]

ii. II。 call with php command line. 用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. III。 run with apache 用apache运行

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

Obviously there is no difference in time cost execution of your test.exe . 显然, test.exe时间成本执行没有区别。 So the difference is related to your web server and how it handles PHP scripts. 因此,差异与您的Web服务器及其处理PHP脚本的方式有关。 Apache is a Thread Safe web server and there are many scheduling and other process tables exist in order to manage Thread safety on it. Apache是​​一个Thread Safe Web服务器,并且存在许多调度和其他进程表,以便管理线程安全性。 Besides, the time that your system costs for searching the path from Apache exe file to your test.exe file may play important role in exceeding the time cost in your case. 此外,您的系统搜索从Apache exe文件到test.exe文件的路径所花费的时间可能会在超出您的情况下的时间成本中发挥重要作用。

You can test your program on other web servers and post the results for exact comparison. 您可以在其他Web服务器上测试您的程序并发布结果以进行精确比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM