Jump to content

Detect Connection Speed


ober

Recommended Posts

Is there a way with PHP (headers, buffers, etc) to detect (in general) the user's connection type?  I want to send the user to a specific page depending on their connection speed and I need it to be a quick test that won't delay page loading too much.

 

I'm even considering loading the main content area with AJAX to avoid major time delays on getting something to the user.

 

So if anyone has a sure-fire way to detect dial-up vs. anything else, I'd appreciate it.

Link to comment
https://forums.phpfreaks.com/topic/65699-detect-connection-speed/
Share on other sites

BTW, I have this script:

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);

 

But I don't know if it's accurate on a dial-up connection.  If any of you have a dialup connection, can you test it for me and post the results?  (www.whproductions.com/speed.php)

Not as far as i am aware..

all the speed detected do basically the same thing as you current script..

 

EDIT:

the larger the number of bytes you use for the speed test the closer to the true speed.

for JAVA solution would probably work better!...

 

as for the current script maybe adding a header to clear the cache

	header("Pragma: public");
	header("Expires: 0");
	header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
	header("Cache-Control: private",false);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.