d22552000 Posted October 6, 2008 Share Posted October 6, 2008 Well, I have a problem with rounding time + microtime. You will see what I mean below. After much debugging I wrote this stupid thing, even though... IT USED TO BE ABLE TO JUST WRITE "echo $totaltime;" It for some reason does this now... (THE PAGES TAKE ABOUT 4 SECONDS TO LOAD) if ($totaltime<1) { $TEMPORARY = $totaltime; $NEW = round($TEMPORARY,6); echo "DEBUG MODE<br />"; echo "COME ON...: " . round($NEW) . "<br />"; // THIS ECHOS 0 echo "NEW: $NEW<br />"; // THIS ECHOS 4.6E-5 echo "OLD: $totaltime<br />"; // THIS ECHOS 4.60555267334E-5 } PLEASE HELP ME!!! (need it asap, this is on a PRODUCTION BOX (PHP 5)) Quote Link to comment https://forums.phpfreaks.com/topic/127313-for-some-reason-round-will-not-give-me-time-anymore-please-view-code/ Share on other sites More sharing options...
akitchin Posted October 6, 2008 Share Posted October 6, 2008 that's technically correct. it's rounding to the 6th decimal place, which in this instance only yields two digits since your number is: 0.000046[055526733] are you looking for a certain number of significant digits? Quote Link to comment https://forums.phpfreaks.com/topic/127313-for-some-reason-round-will-not-give-me-time-anymore-please-view-code/#findComment-658538 Share on other sites More sharing options...
d22552000 Posted October 6, 2008 Author Share Posted October 6, 2008 I want a number like this (since it is the total time taken to display the page) 4.1615 (or something like that) I even tried printf("The page took %f seconds to load",$totaltime,"formatstring"); Quote Link to comment https://forums.phpfreaks.com/topic/127313-for-some-reason-round-will-not-give-me-time-anymore-please-view-code/#findComment-658547 Share on other sites More sharing options...
AndyB Posted October 7, 2008 Share Posted October 7, 2008 I use this at the page start: $starttime = explode(' ', microtime()); $starttime = (float)$starttime[1] + (float)$starttime[0]; and this at the page end: $endtime = explode(' ', microtime()); $endtime = (float)$endtime[1] + (float)$endtime[0]; $totaltime = number_format(($endtime - $starttime), 3, '.', ''); echo "<p>My server generated this page in $totaltime seconds</p>"; Does that help? Quote Link to comment https://forums.phpfreaks.com/topic/127313-for-some-reason-round-will-not-give-me-time-anymore-please-view-code/#findComment-658660 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.