ober Posted August 19, 2007 Share Posted August 19, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/65699-detect-connection-speed/ Share on other sites More sharing options...
ober Posted August 19, 2007 Author Share Posted August 19, 2007 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) Quote Link to comment https://forums.phpfreaks.com/topic/65699-detect-connection-speed/#findComment-328131 Share on other sites More sharing options...
MadTechie Posted August 19, 2007 Share Posted August 19, 2007 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); Quote Link to comment https://forums.phpfreaks.com/topic/65699-detect-connection-speed/#findComment-328135 Share on other sites More sharing options...
ghurty Posted August 19, 2007 Share Posted August 19, 2007 I just checked with a tetherd cell phone connection, and all it did was display the speed "Download speed is 16.522 kb/s". Quote Link to comment https://forums.phpfreaks.com/topic/65699-detect-connection-speed/#findComment-328140 Share on other sites More sharing options...
ober Posted August 19, 2007 Author Share Posted August 19, 2007 Thanks. Anyone else? Quote Link to comment https://forums.phpfreaks.com/topic/65699-detect-connection-speed/#findComment-328280 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.