php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63699 Poor date()/etc performance [PATCH]
Submitted: 2012-12-05 15:52 UTC Modified: 2013-01-06 02:12 UTC
Votes:4
Avg. Score:5.0 ± 0.0
Reproduced:4 of 4 (100.0%)
Same Version:4 (100.0%)
Same OS:4 (100.0%)
From: njaguar at gmail dot com Assigned: lstrojny (profile)
Status: Closed Package: Performance problem
PHP Version: 5.4.9 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: njaguar at gmail dot com
New email:
PHP Version: OS:

 

 [2012-12-05 15:52 UTC] njaguar at gmail dot com
Description:
------------
More info: http://news.php.net/php.internals/64147

I ended up digging deeper and created a patch for this.

Summary of changes:
- Created a new tz_checked_valid flag on the global date structure
- Created a callback method when date.timezone is modified by the ini (set)
- Callback checks validity if set during runtime, and will error (with line number) accordingly. This is probably useful for some users that might no otherwise have realized they made a mistake on their ini_set() line in their code.
- In guess_timezone(), if tz_checked_valid is not set, attempts to validate, errors if cannot.

As previously noted from my benchmarks, over 1 million runs, it increased performance from:
date                    : 1.751 sec
strftime                : 1.872 sec
strtotime               : 3.195 sec

to:
date                    : 1.238 sec
strftime                : 0.999 sec
strtotime               : 2.337 sec

Here is a test case to show that it will not blow up on invalid timezones, and revalidates accordingly:

<?php
ini_set('date.timezone', 'FAKE_TIMEZONE');
echo date('F j, Y, g:i a');

ini_set('date.timezone', 'America/Chicago');
echo date('F j, Y, g:i a');
?>

Note: If the ini is actually set wrong, it will not error until they call a date function that makes use of the timezone, just like before.

Thanks!

Test script:
---------------
$c = 1000000;
for($i=0; $i<$c; $i++) date('F j, Y, g:i a');

etc..

Expected result:
----------------
Performance results are benchmarked and displayed in the general description

Actual result:
--------------
Performance results are benchmarked and displayed in the general description

Patches

date_perf_patch2 (last revision 2012-12-05 15:53 UTC by njaguar at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-05 22:51 UTC] johannes@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: derick
 [2013-01-04 16:58 UTC] lstrojny@php.net
-Assigned To: derick +Assigned To: lstrojny
 [2013-01-06 02:12 UTC] lstrojny@php.net
-Status: Assigned +Status: Closed
 [2013-01-06 02:12 UTC] lstrojny@php.net
The fix for this bug has been committed.

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.

Fixed with some modifications in 5.4, 5.5 and master.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 04:01:28 2024 UTC