Jump to content

Page loading in 0 or 3E-05 seconds?


lucasl

Recommended Posts

Hi,
I'm doing a page load time on my website, but for some reason its not working. When I round the final time result to 4 or less, it just displays zero. When its five, it shows '3E-05'. Also, echo 'Page loaded in $fintime secs.' doesn't display the variable, it just displays $fintime. Here's my code.
[code]
//At the top:
<?
  $mtime = explode(' ', microtime());
  $starttime = $mtime[0] + $mtime[1];
?>
//At the bottom:
  <?
    $mtime = explode(' ', microtime());
    $fintime = $mtime[0] + $mtime[1];
    $loadtime = $fintime - $starttime;
    $loadtime = round($loadtime, 5);
    echo 'Page loaded in '.$loadtime.' secs.';
  ?>
[/code]
If you want to see my html as well, view the page source source [url=http://www.freesoft.logical-host.com]here[/url].
Link to comment
https://forums.phpfreaks.com/topic/30930-page-loading-in-0-or-3e-05-seconds/
Share on other sites

Your script is all a bit backward. Try...

[code]
<?php
  // top
  $time = explode(' ', microtime());
  $start = $time[1] + $time[0];
?>

<?php
  // bottom
  $time = explode(' ', microtime());
  $finish = $time[1] + $time[0];
  $total_time = round(($finish - $start), 5);
  echo "Page loaded in $total_time secs.";
?>
[/code]

PS and OT but, also note that using the full <?php tags enables syntax highlighting on the board. Its a good idea to get into that habbit of coding with it anyway as its guarenteed to work on all servers.
Here's an interesting note, look at this:
[code]Starttime Raw: 0.43816100, 1166334795 Fintime Raw: 0.43820800, 1166334795Page loaded in 5E-05 secs. fin: 1166334795.44 start: 1166334795.44[/code]
Thats all the variables. Raw is the array result of millisecs seperated by a comma. I think something is wrong with my millisecs command

EDIT: And by millisecs I mean microtime():)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.