Bug->Req #79030 [Nab->ReO]: Upgrade apache2handler's php_apache_sapi_get_request_time to return usec
| From: | requinix@php.net | Date: | Fri, 27 Dec 2019 04:01:10 +0000 |
| Subject: | Bug->Req #79030 [Nab->ReO]: Upgrade apache2handler's php_apache_sapi_get_request_time to return usec | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-224544@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79030&edit=1
ID: 79030
Updated by: requinix@php.net
Reported by: herbert at groot dot jebbink dot nl
-Summary: $_SERVER['REQUEST_TIME_FLOAT'] and microtime(TRUE)
combination problem
+Summary: Upgrade apache2handler's
php_apache_sapi_get_request_time to return usec
-Status: Not a bug
+Status: Re-Opened
-Type: Bug
+Type: Feature/Change Request
Package: *General Issues
Operating System: ChromeOS / Crostini / Debian 10
PHP Version: 7.4.1
Block user comment: N
Private report: N
New Comment:
> The SAPI is apache2handler, that one gives indeed msec als precision.
>
> https://github.com/php/php-src/blob/PHP-7.4.1/sapi/apache2handler/sapi_apache2.c#L360!Ž'Á[y•
> tpLæÜ6ã
Also https://apr.apache.org/docs/apr/1.7/group__apr__time.html
which shows the time from apr_time_as_msec is truncated to milliseconds.
Previous Comments:
------------------------------------------------------------------------
[2019-12-27 03:45:11] bugreports at gmail dot com
> The SAPI is apache2handler, that one gives indeed msec als precision.
> It seems usec is also available
apache2handler on all of my setups is using usec
this is a microtime(TRUE) based runtime measurement from a custom header
0.0245 / 0.0152
the first number is based on $_SERVER['REQUEST_TIME_FLOAT']
the second one is based on microtime(TRUE) as first codeline
--------------------
$cms_stop_microtime = microtime(TRUE);
$runtime_total = round(($cms_stop_microtime - $_SERVER['REQUEST_TIME_FLOAT']), 4);
$tuntime_cms = round(($cms_stop_microtime - $cms_startup_microtime), 4);
--------------------
this configures a additional http header which is also usec
Header set "X-Response-Time" "%D us"
X-Response-Time: D=25726 us
------------------------------------------------------------------------
[2019-12-27 03:26:50] herbert at groot dot jebbink dot nl
The SAPI is apache2handler, that one gives indeed msec als precision.
https://github.com/php/php-src/blob/PHP-7.4.1/sapi/apache2handler/sapi_apache2.c#L360
It seems dat usec is also available
http://apr.apache.org/docs/apr/1.5/group__apr__time.html
------------------------------------------------------------------------
[2019-12-26 08:23:26] requinix@php.net
REQUEST_TIME_FLOAT is not rounded.
To make sure, what SAPI are you using for the web side? One can define its own means of determining
the request time, and if it does not then PHP falls back to gettimeofday.
https://github.com/php/php-src/blob/PHP-7.4.1/main/SAPI.c#L1083
------------------------------------------------------------------------
[2019-12-26 06:00:31] herbert at groot dot jebbink dot nl
gettimeofday(2) may not be accurate at sub-millisecond level, but with 2 sequential calls the last
one will not be lower then the first one.
I think it is caused by the fact that $_SERVER['REQUEST_TIME_FLOAT'] is rounded to
milliseconds and microtime(TRUE) is not.
------------------------------------------------------------------------
[2019-12-25 09:12:46] requinix@php.net
Those two are backed by gettimeofday(2), which is not suitable for measuring time intervals to
sub-millisecond precision.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=79030
--
Edit this bug report at https://bugs.php.net/bug.php?id=79030&edit=1