测量PHP脚本的时间-使用$ _SERVER ['REQUEST_TIME'] [英] Measuring the time of PHP scripts - Using $_SERVER['REQUEST_TIME']

查看:114
本文介绍了测量PHP脚本的时间-使用$ _SERVER ['REQUEST_TIME']的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这种方法是衡量脚本的可靠方法吗?

Are this methods a reliable way to measure a script:

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

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

应该使用哪个?

每个人有什么区别?

它们返回非常不同的测量值.

They return very different measurements.

推荐答案

  1. $time = ($_SERVER['REQUEST_TIME_FLOAT'] - $_SERVER['REQUEST_TIME']);

这将永远不会给您PHP脚本的执行时间.因为这两个值都用于存储请求开始.区别在于,$_SERVER['REQUEST_TIME_FLOAT']更精确,并且以微秒精度存储时间值,而$_SERVER['REQUEST_TIME']以秒为单位.

This will never give you execution time of you PHP script. Because both the values are used for storing start of request. The difference is, $_SERVER['REQUEST_TIME_FLOAT'] is more precise and stores time value with microsecond precision, while $_SERVER['REQUEST_TIME'] in seconds.

  1. $time = (microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']);

我想这是在PHP脚本末尾应使用的方式,我想您知道原因.

I guess this is what should be used at the end of the PHP script and I think you know why.

还请记住,自PHP 5.4.0起,可以使用$ _SERVER ['REQUEST_TIME_FLOAT'].

Also keep in mind $_SERVER['REQUEST_TIME_FLOAT'] is available since PHP 5.4.0.

这篇关于测量PHP脚本的时间-使用$ _SERVER ['REQUEST_TIME']的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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