note 85521 deleted from function.strtotime by danbrown

From: Date: Mon, 18 May 2009 02:19:05 +0000
Subject: note 85521 deleted from function.strtotime by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155642@lists.php.net to get a copy of this message
Note Submitter: rdheijer at reestyle dot net ---- Rather a notice, but maybe important to share with everyone. I am currently stationed at a company that works with php on an IBM i5. Now there are a few things that run slower. strtotime() is a good example. Running the script we saw that this function on an i5 consumes a lot of time when you have a lot of records to process. Using it on a loopcount of 3000 (which we took as reference), we noticed that the script took 4 seconds longer than without the conversion. Imagine you doing this in an environment with more than just this conversion. We came up with a simple solution: Calculate the date by using a preformatted string (preferably the datetime field directly from MySQL, just for the sake of performance). We needed this conversion for our webapplication. Creating this function saves us 4 seconds on 3000 loops. Since we really need that more than once per loop, imagine the load (for your info, the script now took only 1 second in stead of 5, each loop about 0.0009s). What you need to do is: - Multiply the number of years minus 1 (you are in the last year) since 1970 with the number of days and then the number of seconds per day (don't foget leap years) - Create a loop counting cumulating the number of days per months minus one (you are in the current month) and multiply it by the number seconds per day - Add the number of days minus one (you are in the current day) and multiply that by the number of seconds in a day - Multiply the number of hours by the number of seconds in an hour (normally 3600) - Multiply the minutes by the number of seconds in a minute (which would still be 60) - Add the seconds... Hey, wait, when i do a backward conversion with date(.., $thatCalculatedTimestamp) it shows the right date and all, but it's one hour ahead. True, you still need to adjust daylight saving time if your country uses this method. Ok, that was a long story, but I just hope it is helpful. Maybe it'll also create performance gain on other machines when you need this functionality. If you have an other suqqgestion, please, I'm all ears. Reerun...

« previous php.notes (#155642) next »