加载PHP页面的时间Apache服务器 [英] Loading time of php page in apache server

查看:171
本文介绍了加载PHP页面的时间Apache服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能知道加载一个PHP页面由Apache服务器所花费的时间?有Apache服务器内部产生了这是在Apache服务器?

Is it possible to know the time taken by Apache server to load a PHP page? Is there any log file generated inside Apache server for every page which is running under Apache server?

推荐答案

我要假设你想知道花了多长时间了PHP生成的页面。

I'm going to assume you wish to know how long it took for PHP to generate the page.

在脚本开始,因为5.1,有一个在 $ _ SERVER条目 可以使用,名为 REQUEST_TIME 。它包含当请求开始的时间。在脚本结束时,你可以计算出它像这样:

When the script starts, since 5.1, there's an entry in $_SERVER you can use, called REQUEST_TIME. It contains the time when the request was started. At the end of your script you can calculate it like so:

$time_taken = time() - $_SERVER['REQUEST_TIME'];

显然,这不是很准确,因此,新的 REQUEST_TIME_FLOAT 在PHP 5.4中引入:

Obviously, this is not very accurate and therefore the newer REQUEST_TIME_FLOAT was introduced in PHP 5.4:

$time_taken = microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'];

有关<

if (!isset($_SERVER['REQUEST_TIME_FLOAT'])) {
    $_SERVER['REQUEST_TIME_FLOAT'] = microtime(true);
}

更新

要让阿帕奇为你做这个,你可以添加%T 和/或%D 日志格式选项​​,如:

To let Apache do this for you, you can add the %T and/or %D log format option, e.g.

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" **%T/%D**" combined

%T 选项,您可以登录所采取的秒数,%D 日志微秒(自阿帕奇2)。

The %T option lets you log the number of seconds taken and %D logs the microseconds (since Apache 2).

另请参阅:的多久需要服务的请求

这篇关于加载PHP页面的时间Apache服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆