php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62507 $_SERVER['REQUEST_TIME'] under mod_php5 returns miliseconds instead of seconds
Submitted: 2012-07-08 13:30 UTC Modified: 2012-07-08 17:08 UTC
From: theultramage at gmail dot com Assigned: felipe (profile)
Status: Closed Package: Apache2 related
PHP Version: 5.4.4 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: theultramage at gmail dot com
New email:
PHP Version: OS:

 

 [2012-07-08 13:30 UTC] theultramage at gmail dot com
Description:
------------
http://git.php.net/?p=php-src.git;a=commitdiff;h=f89effd2a83de2b1d6381f9b9403a8328e0998b6
On 6.nov.2010 Ilia Alshanetsky "Updated _SERVER['REQUEST_TIME'] to include microsecond precision". This introduced a breaking change - since then variable returns miliseconds instead of seconds.

http://git.php.net/?p=php-src.git;a=commitdiff;h=86c44e119fd71eeed6f3bc213d544a06cc4a13e5
On 23.jun.2011 someone finally noticed, and he "Fixed a bug with calculation of REQUEST_TIME in apache2". However, he only fixed apache2handler and omitted apache2filter.

The bug breaks existing code that uses $_SERVER['REQUEST_TIME'] in timestamp comparisons and assumes that its value is in seconds. I tested the attached patch and it fixes the issue (hopefully not introducing other issues).
PS: $_SERVER['REQUEST_TIME_FLOAT'] is also affected.

Test script:
---------------
<?php
	$rt = $_SERVER['REQUEST_TIME'];
	$now = time();

	echo $rt."\n";
	echo $now."\n";
	echo ( strlen((string)$rt) == strlen((string)$now) ) ? "OK" : "Error!";
?>


Expected result:
----------------
1341752154
1341752154
OK


Actual result:
--------------
CLI/CGI:
1341752154
1341752154
OK


MOD_PHP5:
1341752154539
1341752154
Error!


Patches

patch-sapi-apache2filter-sapi_apache2.c (last revision 2012-07-08 13:30 UTC by theultramage at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-08 17:07 UTC] felipe@php.net
Automatic comment on behalf of felipensp@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=2019062cfc6e4b4832aaca3b73891d93adc115a8
Log: - Fixed bug #62507 (['REQUEST_TIME'] under mod_php5 returns miliseconds instead of seconds)
 [2012-07-08 17:08 UTC] felipe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: felipe
 [2012-07-08 17:08 UTC] felipe@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2014-10-07 23:24 UTC] stas@php.net
Automatic comment on behalf of felipensp@gmail.com
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=2019062cfc6e4b4832aaca3b73891d93adc115a8
Log: - Fixed bug #62507 (['REQUEST_TIME'] under mod_php5 returns miliseconds instead of seconds)
 [2014-10-07 23:34 UTC] stas@php.net
Automatic comment on behalf of felipensp@gmail.com
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=2019062cfc6e4b4832aaca3b73891d93adc115a8
Log: - Fixed bug #62507 (['REQUEST_TIME'] under mod_php5 returns miliseconds instead of seconds)
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Dec 05 18:03:37 2021 UTC