note 85521 added to function.strtotime

From: Date: Wed, 03 Sep 2008 18:48:39 +0000
Subject: note 85521 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-144124@lists.php.net to get a copy of this message
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... ---- Server IP: 213.249.64.162 Probable Submitter: 85.147.204.71 ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- https://master.php.net/note/edit/85521 Del: integrated -- https://master.php.net/note/delete/85521/integrated Del: useless -- https://master.php.net/note/delete/85521/useless Del: bad code -- https://master.php.net/note/delete/85521/bad+code Del: spam -- https://master.php.net/note/delete/85521/spam Del: non-english -- https://master.php.net/note/delete/85521/non-english Del: in docs -- https://master.php.net/note/delete/85521/in+docs Del: other reasons-- https://master.php.net/note/delete/85521 Reject -- https://master.php.net/note/reject/85521 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#144124) next »