<script language="JavaScript"> now=new Date(); var startms=now.getTime(); </script>End your form (which should be near the bottom of the page) with this code. It stuffs the start and end times into hidden fields in the form. In the "document.yourform" lines, you MUST replace "yourform" with the exact name of your form for this to work. You can actually access any field in the form this way; consider the possibilities.
<input type="hidden" name="firstms"> <input type="hidden" name="lastms"> <script language="JavaScript"> later=new Date(); var endms=later.getTime(); document.yourform.firstms.value=startms; document.yourform.lastms.value=endms; </script> </form>
<cfif form.lastms is not form.firstms> <cfset Loadms = form.lastms - form.firstms> <cfelse> <cfset Loadms = 1> </cfif>You can divide the result into the size of the page in bytes to get the connection speed in bytes per millisecond which becomes KBytes per second. For example, 60000 bytes / 6000 milliseconds [that's 6 seconds] reflects a connection speed of 10KBytes per second.
<!--- Replace with the size of YOUR form page in bytes; I hope it's smaller ---> <cfset FormBytes = 26459> <cfset KBytesPs = FormBytes/Loadms>Add this if you want to tell the user what you've learned.
<cfoutput><p> The form that fed this page took #Loadms# milliseconds to load.<br> If it's #FormBytes# bytes, then the speed was: #KBytesPs# KBytes per second.<p> </cfoutput>
<cfset NowDt = now()> <cfset NowDts = DateFormat(NowDt,"YYYY/MM/DD")&" "&TimeFormat(NowDt,"HH:mm:ss")> <cfset RA = "#CGI.remote_addr#"> <cfset RA1 = numberFormat(getToken(#RA#,1,"."),000)> <cfset RA2 = numberFormat(getToken(#RA#,2,"."),000)> <cfset RA3 = numberFormat(getToken(#RA#,3,"."),000)> <cfset RA4 = numberFormat(getToken(#RA#,4,"."),000)> <cfset IP = #RA1#&"."RA2#&"."RA3#&"."RA4#> <cfset Tab = chr(9)> <cfset doline = "#KBytesPs##Tab##NowDts##Tab##IP#">
<cfset YourLog="#getDirectoryFromPath(cf_template_path)#"&"YourLog.txt"> <cfoutput>#YourLog#</cfoutput>This single line creates the file if it doesn't exist adds text to it.
<cffile action="append" file="#YourLog#" output="#doline#" addnewline attributes="normal">In this example, the first column is the speed in KBytes per second, the second is the date/time with just a space separating them, and the third is the IP address. You can read the text file into Excel or copy it into an open spreadsheet. If you highlight and copy the text, go to Excel's menu to keep it from being pasted as HTML by selecting "edit; paste-special; text". If you want people to be able to paste it without going through this step, format the log as a table instead of using tabs. You might also want to round up the speeds to get rid of those long decimals.
92.9752066116 2001/01/08 16:10:06 143.158.254.007 113.255033557 2001/01/08 16:20:20 209.235.109.009 84.5070422535 2001/01/08 16:21:27 207.230.075.195 112.333333333 2001/02/25 15:01:30 127.000.000.001 262.245454545 2001/02/25 15:06:18 127.000.000.001 90.9090909091 2001/02/25 15:56:30 024.214.065.188 83.3333333333 2001/02/25 15:57:27 024.214.065.188Here's an example on this host that shows these techniques at work: YourHome.htm. Once you've seen this, browse yourlog.txt.
A 56Kbit dial-up modem can pass about 5KBytes per second; a T1 connection can pass about 180KBytes per second. The speeds shown here are more typical of a cable modem connection or of a browser that actually resides on the server while you're checking your code (grin). =Marty=
[The offer to browse yourlog.txt was added after publication. The code, except for hidden modifications to satisfy the ISP, remains the same.]