Bug #79030 [Com]: $_SERVER['REQUEST_TIME_FLOAT'] and microtime(TRUE) combination problem

From: Date: Fri, 27 Dec 2019 03:26:50 +0000
Subject: Bug #79030 [Com]: $_SERVER['REQUEST_TIME_FLOAT'] and microtime(TRUE) combination problem
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224542@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 Comment by: herbert at groot dot jebbink dot nl Reported by: herbert at groot dot jebbink dot nl Summary: $_SERVER['REQUEST_TIME_FLOAT'] and microtime(TRUE) combination problem Status: Not a bug Type: Bug 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 It seems dat usec is also available http://apr.apache.org/docs/apr/1.5/group__apr__time.html Previous Comments: ------------------------------------------------------------------------ [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. ------------------------------------------------------------------------ [2019-12-25 06:56:21] herbert at groot dot jebbink dot nl Description: ------------ Sometimes the $_SERVER['REQUEST_TIME_FLOAT'] and microtime(TRUE) combination gives strange results. Below example gives about 1 in 10 times a negative result. Test script: --------------- <?php $script1 = microtime(TRUE); $script2 = file_get_contents('http://localhost/script2.php'); echo $script2 - $script1; ?> <?php echo $_SERVER['REQUEST_TIME_FLOAT']; ?> Expected result: ---------------- 0.00038409233093262 Actual result: -------------- -0.00039100646972656 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79030&edit=1

« previous php.bugs (#224542) next »