note 53189 deleted from function.time by aidan

From: Date: Sat, 08 Oct 2005 01:02:30 +0000
Subject: note 53189 deleted from function.time by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-96602@lists.php.net to get a copy of this message
Note Submitter: Bryan H. ---- I have recently developed a program for sending our e-mail newsletters with phpmailer and using our webservers sendmail capabilities. We had previously been using our in house exchange server and hosting an aspmail application on a separate account with a windows platform. Using our unix web servers has given me greater ability to maintain the subscriber lists in a mysql database instead of ms access and I've taken a great load off of our in house mail server. But ... now it takes a great deal of time for the php mail application I developed to process all the addresses in the database (most lists have 1500 plus subscribers) so I wanted to see exactly how long each list was taking to process. I borrowed bits of different code I found here and tweaked it a bit to calculate the elapsed time from when the page is first envoked until the code finishes executing. I changed it to just return the minutes and seconds. <? $date = getdate(); $hrs = $date['hours']; $min = $date['minutes']; $sec = $date['seconds']; $mon = $date['mon']; $day = $date['mday']; $yr = $date['year']; function calcElapsedTime($time) { // calculate elapsed time (in seconds!) $diff = time()-$time; $daysDiff = 0; $hrsDiff = 0; $minsDiff = 0; $secsDiff = 0; $sec_in_a_day = 60*60*24; while($diff >= $sec_in_a_day){ $daysDiff++; $diff -= $sec_in_a_day; } $sec_in_an_hour = 60*60; while($diff >= $sec_in_an_hour){ $hrsDiff++; $diff -= $sec_in_an_hour; } $sec_in_a_min = 60; while($diff >= $sec_in_a_min){ $minsDiff++; $diff -= $sec_in_a_min; } $secsDiff = $diff; return ($minsDiff.' minute'.(($minsDiff <> 1) ? "s" : "").', '.$secsDiff.' second'.(($secsDiff <> 1) ? "s" : "")); } sleep(15); // use php sleep() function to test $elap_time = calcElapsedTime(mktime($hrs,$min,$sec,$mon,$day,$yr)); echo("<p><b>This page took " . $elap_time . " to fully execute.</b></p>"); ?> Here is the output: This page took 0 minutes, 15 seconds to fully execute. Thanks for all of your contributions.

« previous php.notes (#96602) next »