Get the full commented source code of

HTML5 Suika Watermelon Game

Talking about Php and Tutorials.

One of the hardest script you can find in internet is the one that determines connection speed of a surfer visiting our site.
From today it’s not anymore a problem (even if nobody had nightmares before…) because we will make a php script in order to fill such lack.

Let’s start coding…

 Test finished in $deltat seconds. Your speed is ". round($kb / $deltat, 3)."Kb/s";
?>

Done. Analysis and considerations:

2: Declaring how much Kb I want to transmit to accomplish the test. This value can also be passed in POST or GET. In my example it is declared.

3: I write I am downloading data, and open a comment tag. Everithing I am sending from now on will not be displayed. It’s not necessary, but prevents the browser to be fullfilled of chars.

4: Flush the chache

5-6: Saving actual timestamp

7-9: For $kb times I send 1024 chars (1Kb) and flush the cache

11-12: Saving actual timestamp

13: Calculating difference between start and finish timestamps

14: Closing comment tag and writing test result, calculated as Kb/time

Done… very easy isn’t it?

Considerations and exceptions

I wasn’t able to get reliable speed values with $kb under 512. I noticed the higher this number, the more reliable the result.

In some php configurations, those with output buffering to “On”, php executes before sending headers, cookies, and so on, and the time calculated in that way is the time of pure execution (excluding tranfers). Disabling output buffering, however, results are reliable.

You can try the script at this page.

Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.