# date/strtotime poor performance - further digging (v 5.4.9) [PATCH]

- Thread: https://externals.io/message/64160
- Original archive: https://news-web.php.net/php.internals/64160
- Started by Paul Taulborg on 2012-12-05T15:54:30+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #64160 — Paul Taulborg — 2012-12-05T15:54:30+00:00

URL: https://externals.io/message/64160#64160

I ended up digging deeper and created a patch for this, and have
created a bug with the patch attached.
https://bugs.php.net/bug.php?id=63699

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!
