|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-08-15 13:48 UTC] robin_fernandes at uk dot ibm dot com
Description: ------------ Test http://lxr.php.net/source/php-src/ext/date/tests/bug35885.phpt compares two time stamps representing the current time. However, these timestamps are seized in separate statements. The comparison fails intermittently, because the seconds occasionally tick over between the two calls. Below is bug35885.phpt enclosed in a loop to prove that it fails intermittently. It will break out of the loop on failure. Expected time to failure is less than 10 seconds. Reproduce code: --------------- <?php date_default_timezone_set("UTC"); while (true) { $ts = date(DATE_ISO8601, strtotime('NOW')); $ts2 = date(DATE_ISO8601, time()); $res = ($ts == $ts2); var_dump($res); if (!$res) { var_dump($ts); var_dump($ts2); break; } } ?> Expected result: ---------------- N/A (loop) Actual result: -------------- bool(true) bool(true) [...] bool(true) bool(false) string(24) "2007-08-15T13:26:05+0000" string(24) "2007-08-15T13:26:06+0000" PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 21 07:00:01 2025 UTC |
Below is a suggested patch which modifies the test to allow for a 1 second margin between the timestamps. I have confirmed the resulting test passes consistently on Windows on PHP 5.2.3, but have done no further testing. Index: C:/php5-latest-phpt/ext/date/tests/bug35885.phpt =================================================================== --- C:/php5-latest-phpt/ext/date/tests/bug35885.phpt (revision 13029) +++ C:/php5-latest-phpt/ext/date/tests/bug35885.phpt (working copy) @@ -4,15 +4,15 @@ <?php date_default_timezone_set("UTC"); -$ts = date(DATE_ISO8601, strtotime('NOW')); -$ts2 = date(DATE_ISO8601, time()); +$ts = strtotime('NOW'); +$ts2 = time(); -$res = ($ts == $ts2); +$res = ($ts == $ts2) || ($ts == $ts2-1); var_dump($res); if (!$res) { - var_dump($ts); - var_dump($ts2); + var_dump(date(DATE_ISO8601, $ts)); + var_dump(date(DATE_ISO8601, $ts2)); } ?>