Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

How do I detect the network speed of a visitor?

Hello,
How do I detect the connection speed of a user that is visiting my page. Baiscally I want to know if they are dial-up, or high-speed of some sort. I need this for an analytics packaage I am writing.

Worth 500 points.

Thanks,
Rick
0
richardsimnett
Asked:
richardsimnett
  • 2
1 Solution
 
aseusaincCommented:
You cant get that info directly.  Best you could do is create a bandwidth test, by maybe having them upload a file, and determining the time it took to upload X bytes.  But there is no #users_connection_speed# type variable.
0
 
richardsimnettAuthor Commented:
aseusainc,
I have found that the solution is to purchase an aggregate database containing ip ranges, and associated net speeds. Its simply a matter of having this table in a database, and querying the incoming IP against it. It has proven to be about 90% accurate so far.

-Rick
0
 
aseusaincCommented:
Spiffy, what database did you end up going with?  The ones I saw seemed pretty darn pricey :(
0
 
abogothyCommented:
I've found a solution which is simple, but gives usable connection speed info. Put lines following lines into php:

function microtime_diff($a, $b) {
list($a_dec, $a_sec) = explode(" ", $a);
list($b_dec, $b_sec) = explode(" ", $b);
return $b_sec - $a_sec + $b_dec - $a_dec;
}

function test_speed($test_size) {
flush();
$start_time = microtime();
$comment = "<!--O-->";
$len = strlen($comment);
for($i = 0; $i < $test_size; $i += $len) {
echo $comment;
}
flush();
$duration = microtime_diff($start_time, microtime());
if($duration != 0) {
return $test_size / $duration / 1024;
}
else {
return log(0);
}
}

$speed = test_speed(1024);
if($speed > 50) { // a fast connection, send more byte for more accuracy
$speed = test_speed(10240);
if($speed > 500) { // a really fast connection, send even more byte for
more accuracy
$speed = test_speed(102400);
}
}
echo sprintf("Download speed is %0.3f kb/s", $speed);
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now