【发布时间】:2016-04-26 14:12:18
【问题描述】:
我有一个 php 脚本,它运行一个 bash 脚本来终止一个进程并启动一个新的进程实例。不幸的是,在尝试运行它时,它需要很长时间才能运行。我如何确定原因?它是 Debian 7 专用服务器上的 apache2 服务器。
php 脚本:
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
$start = microtime(TRUE);
if (isset($_GET['resetnow'])) {
$myreset = $_GET['resetnow'];
if ($myreset == "now") {
$cmd=getcwd()."/resetut.sh 2>&1";
exec($cmd, $output, $return_var);
$outputstr=implode(",", $output);
$finish = microtime(TRUE);
$totaltime = $finish - $start;
$timetaken = " This script took ".$totaltime." seconds to run";
print $cmd." ".$outputstr.$timetaken;
} else {
print "Didnt receive correct parameters";
}
} else {
print "Undefined";
}
?>
shell脚本:
#!/bin/bash
cd pathto/utorrent
killall utserver
./utstart start
a=$(pgrep utserver)
echo Utorrent restarted as new process $a
不幸的是,输出看起来像这样:
/pathto/resetut.sh 2>&1 Starting utorrent server,
Utorrent restarted as new process 25044 25381
This script took 275.10148310661 seconds to run
太长了。如果从命令行执行 shell 脚本,则只需不到一秒的时间即可完成。
【问题讨论】:
-
从命令行运行 php 脚本与从浏览器启动的运行时间是否相同?
-
它被称为
profiling,并且有一些工具可以做到这一点。谷歌了解更多 -
@Samsquanch 是的,我愿意
-
这个问题可能有很多原因,其中一个是硬件问题,您必须询问原因列表并对其进行处理以忽略其中的每个项目然后剩下的原因应该是原因问题的根源。