PHP在启动过程中的什么时候设置了REQUEST_TIME变量 [英] At what point in the startup process does PHP set the REQUEST_TIME variables

查看:175
本文介绍了PHP在启动过程中的什么时候设置了REQUEST_TIME变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP文档所述,$_SERVER超全局变量数组包含两个元素,分别为REQUEST_TIMEREQUEST_TIME_FLOAT,这两个元素均包含精度不同的请求开始的时间戳.

As noted in the PHP documentation, the $_SERVER superglobal array contains two elements, REQUEST_TIME and REQUEST_TIME_FLOAT, both of which contain the timestamp of the start of the request, in varying precision levels.

我当前正在使用以下代码段,以将服务器生成页面所花费的时间(以毫秒为单位)包含在页面的页脚中:

I am currently using the following snippet to include the time (in milliseconds) it took the server to generate the page in the footer of the page:

round((microtime(true)-$_SERVER['REQUEST_TIME_FLOAT'])*1000,2);

它返回一个准确的值(无法真正检查,但似乎与浏览器开始加载页面所需的时间相匹配),但是我想知道$_SERVER['REQUEST_TIME']$_SERVER['REQUEST_TIME_FLOAT']变量在哪个确切时刻执行包含时间戳记?尽管我认为这些时间戳记之间的差异并不大,但我想知道时间戳记在哪一刻.是发送请求的时间,接收请求的时间,PHP开始解析文档的时间还是其他时间?

It returns an accurate value (can't really check, but it seems to match the time it takes the browser to start loading the page), but I am wondering which exact moment do the $_SERVER['REQUEST_TIME'] and $_SERVER['REQUEST_TIME_FLOAT'] variables contain the timestamp of? While I believe that the differences between those timestamps aren't significant, I would like to know which moment is the timestamp taken at. Is it the time when the request was sent, when the request was received, when PHP started parsing the document or something else?

推荐答案

大多数情况下,通过检查PHP源代码,它似乎都是从SAPI本身(即来自Apache,Nginx,CLI服务器和CGI)获取初始请求时间的. ..等

By checking PHP source code it seems most of the times it gets the initial request time from the SAPI itself - meaning from Apache, Nginx, CLI server, CGI... etc.

来源:

  • $_SERVER['REQUEST_TIME'] definition
  • sapi_get_request_time() (SG() stands for "SAPI Global [value]")
  • php_apache_sapi_get_request_time()
  • sapi_module definitions [1] [2]

这篇关于PHP在启动过程中的什么时候设置了REQUEST_TIME变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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