Hi, I've got good news.
I made a post last time asking if anyone would care to share a javascript code that can measure loading time of an HTML page on the client side and pass the value to a MYSQL table through PHP.
I got a wonderful responses from you guys. However, I believe that measuring html page load directly from the PHP can be quite questionable. I'm sure it can only measure the time PHP script has been executed on the server side and not really the html pages being loaded on the client's perspective.
By the way, Thanks to Schwim, Bradgrafelman, Devinemke.
Bradgrafelman is right I need a client side script. I apologize for not being able to articulate my idea.
About the good news...
I found a javascript from javascript.internet.com. I forgot the javascript author but I'll get back to it and post the name later so I can give the credit.
Anyway...
The idea is simple:
First, assign a startTime to a variable.
then, create a loop
then capture an onload event
There's no way I can use the script to pass the value to a PHP script so I modified the script so that a variable can be used to hold the value of the seconds it took for the page to load completely.
Using the same idea...here's my own version of the code:
var startTimer = new Date()
var loopTimer = setInterval("getCurrentTime()",100)
function getCurrentTime(){
var a=Math.floor((new Date()-startTimer)/100)/10
if (a%1 = 0) a += ".0"
window.status = a
}
window.onload = function(){
clearTimeout(loopTimer)
document.getElementById('pageanalyzer')
window.status=""
}
The above code must be put within the <head></head> tag
Then you put the following code at the last part of the html page:
<div id="pageanalyzer">
<script language="javascript" src=pageanalyzer.php></script>
</div>
Now. I can invoke PHP to record an accurate loading time of an HTML page then save it to a Mysql table for future use.
I hope you guys learned from what I've shared to you. Please let me know if I'm fumbling around and sorry for my English.
My next test project is to create a PHP script that will ask for a URL and then test the given URL how long it takes to load on the browser.
Thanks to all of you guys.