/    Sign up×
Community /Pin to ProfileBookmark

Anyone got this script?

Has any one got a script to show the page loading time in seconds?

displays like this: Page loaded in x seconds

Thanks for any help in providing this script.

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@SamMar 31.2004 — I don't, but I would say your best bet would be to set a variable with the time at the very first line of your php, then another at the very end, then subtract the two. that should take care of it.
Copy linkTweet thisAlerts:
@ConorMar 31.2004 — if you want in microseconds

[code=php]
<?php

function getload()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}

$time_start = getload();

//your code here


$time_end = getload();
$time = $time_end - $time_start;

echo "Page loaded in $time seconds";
?>
[/code]


or just seconds

[code=php]
<?php

function getload()
{
list($usec, $sec) = explode(" ", time());
return ((float)$usec + (float)$sec);
}

$time_start = getload();

//your code here


$time_end = getload();
$time = $time_end - $time_start;

echo "Page loaded in $time seconds";
?>
[/code]
Copy linkTweet thisAlerts:
@The_CheatMar 31.2004 — but isn't that just the time it took to execute the script on the server, and not the actual loading time..?
Copy linkTweet thisAlerts:
@ConorMar 31.2004 — its the same as the loading time its like generation time. The time the script starts to the time it ends will be the time it takes to load up the page.
Copy linkTweet thisAlerts:
@pyroApr 01.2004 — [i]Originally posted by RefreshF5 [/i]

[B]The time the script starts to the time it ends will be the time it takes to load up the page. [/B][/QUOTE]
No, that's not correct. The Cheat had it right - that number will be the time it took for the server to process the page, which is [i]not[/i] the same as load time. Load time would have to include the amount of time it took the user to download the page (and the browser to render it) from the moment it sent a request for it. And even this would only work (and would require different code) if the users computer's clock was [i]exactly[/i] synchronized with the server's clock - not likely at all.
Copy linkTweet thisAlerts:
@ConorApr 01.2004 — it is generation time then right?
Copy linkTweet thisAlerts:
@pyroApr 01.2004 — Yep ?
Copy linkTweet thisAlerts:
@ConorApr 01.2004 — yeah i use it on my forums to show page generation time shouldve mentioned that sorry for not being clear
Copy linkTweet thisAlerts:
@sciguyryanauthorApr 01.2004 — Thank you very much RefreshF5 for the code and, everyone else for your help ?
Copy linkTweet thisAlerts:
@ConorApr 01.2004 — no problem happy to help.
×

Success!

Help @sciguyryan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...