473,386 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

detect internet speed with php

Hi guys,
Is it possible to know the internet speed of the visitors with php?

Thanx
--
Yang
Jul 17 '05 #1
13 22976
Yang Li Ke wrote:
Hi guys,
Is it possible to know the internet speed of the visitors with php?

No. There are too many things that have to happen to try to determine
the speed of the visitor. And most of those things, PHP has no access to.

--
Randy

Jul 17 '05 #2
Something like this might given you a sense of how fast the connection is:

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

I have the code set up here: http://www.conradish.net/speed.php. On my cable
connection I get around 300 kb/s, which is about right.

Uzytkownik "Yang Li Ke" <ya******@sympatico.ca> napisal w wiadomosci
news:v7******************@news20.bellglobal.com...
Hi guys,
Is it possible to know the internet speed of the visitors with php?

Thanx
--
Yang

Jul 17 '05 #3
"Chung Leong" <ch***********@hotmail.com> wrote in message
news:_f********************@comcast.com...
Something like this might given you a sense of how fast the connection is:

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

I have the code set up here: http://www.conradish.net/speed.php. On my cable connection I get around 300 kb/s, which is about right.

Uzytkownik "Yang Li Ke" <ya******@sympatico.ca> napisal w wiadomosci
news:v7******************@news20.bellglobal.com...
Hi guys,
Is it possible to know the internet speed of the visitors with php?

Thanx
--
Yang



Interesting concept,

when I test your link, I average 240, but I am on 3 Mbit

when I run it localy with my test server, GigaBit from my desktop to 1
switch to server, I get 190

hmm, I think it is rather testing execution speed.
--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #4
I wonder. According to the PHP manual, flush() is supposed to flush the
server's buffer as well. Presumably the function wouldn't return until it
has received an acknowledgement for the last packet sent.

I tried adding ob_start("ob_gzhandler") to the beginning of the file. The
measured speed increased nearly ten-fold. So I don't think it's testing the
execution speed.

Uzytkownik "CountScubula" <me@scantek.hotmail.com> napisal w wiadomosci
news:Uz******************@newssvr25.news.prodigy.c om...
Interesting concept,

when I test your link, I average 240, but I am on 3 Mbit

when I run it localy with my test server, GigaBit from my desktop to 1
switch to server, I get 190

hmm, I think it is rather testing execution speed.
--
Mike Bradley
http://www.gzentools.com -- free online php tools

Jul 17 '05 #5
"Chung Leong" <ch***********@hotmail.com> wrote in message
news:NJ********************@comcast.com...
I wonder. According to the PHP manual, flush() is supposed to flush the
server's buffer as well. Presumably the function wouldn't return until it
has received an acknowledgement for the last packet sent.

I tried adding ob_start("ob_gzhandler") to the beginning of the file. The
measured speed increased nearly ten-fold. So I don't think it's testing the execution speed.

Hmm, here is an idea, havent done any code, I am going to sleep, diving in
the morning.

what if you were to send a header with a timestamp:

fist call to page:
Location:
http://www.blablabla.com/test.php?action=loop&step=1&ts[1]=microtime

next call to page
Location:
http://www.blablabla.com/test.php?action=loop&step=2&ts[1]=microtime&ts[2]=m
icrotime

loop a couple times of times, average out the time stamps for an average
page redirct.

this will be used a reference to delays, overhead etc...

then do this header
Location: http://www.blablabla.com/test.php?ac...avg=_avg_stamp

then for that page, send a lot of header data:
for ($i=0; $i < 100; $i++)
{
$head = "X-SpeedTest: --- speed test $i---";

$headerSize += strlen($head) + 2;
header($head);
}

header("Location:
http://www.blablabla.com/test.php?ac...=mictotime&ds=
$headerSize
then the last call to the page:

$timeElapsed = (microtime() - $_GET['ts']) - $_GET['avg'];
$dataSize = $_GET['ds'];

hmm, then I think we would have a size of data sent, and time to send?

just a thought.....What do you think?

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #6
Ok, I just got back, and tried to code it, let me know if this is any good.

you can test it here:

http://www.gzentools.com/test/speed.php

and the source is here:

http://www-3.gzentools.com/snippetvi...=speedtest.php

--
Mike Bradley
http://www.gzentools.com -- free online php tools

"CountScubula" <me@scantek.hotmail.com> wrote in message
news:Zx******************@newssvr25.news.prodigy.c om...
"Chung Leong" <ch***********@hotmail.com> wrote in message
news:NJ********************@comcast.com...
I wonder. According to the PHP manual, flush() is supposed to flush the
server's buffer as well. Presumably the function wouldn't return until it has received an acknowledgement for the last packet sent.

I tried adding ob_start("ob_gzhandler") to the beginning of the file. The measured speed increased nearly ten-fold. So I don't think it's testing the
execution speed.

Hmm, here is an idea, havent done any code, I am going to sleep, diving in
the morning.

what if you were to send a header with a timestamp:

fist call to page:
Location:
http://www.blablabla.com/test.php?action=loop&step=1&ts[1]=microtime

next call to page
Location:

http://www.blablabla.com/test.php?action=loop&step=2&ts[1]=microtime&ts[2]=m icrotime

loop a couple times of times, average out the time stamps for an average
page redirct.

this will be used a reference to delays, overhead etc...

then do this header
Location: http://www.blablabla.com/test.php?ac...avg=_avg_stamp

then for that page, send a lot of header data:
for ($i=0; $i < 100; $i++)
{
$head = "X-SpeedTest: --- speed test $i---";

$headerSize += strlen($head) + 2;
header($head);
}

header("Location:
http://www.blablabla.com/test.php?ac...=mictotime&ds= $headerSize
then the last call to the page:

$timeElapsed = (microtime() - $_GET['ts']) - $_GET['avg'];
$dataSize = $_GET['ds'];

hmm, then I think we would have a size of data sent, and time to send?

just a thought.....What do you think?

--
Mike Bradley
http://www.gzentools.com -- free online php tools

Jul 17 '05 #7
Hmmm, using the header might be a better idea than sending the test bytes as
HTML comment, as it seems the browser would save the comment tags into the
DOM (thus eat up memory). A bit cleaner too to redirect to a separate page.

Tried your page. It's reporting that my 3 mbit connection is capable of
downloading 1.8 k per second. Perhaps a larger amount of test data is
needed?

Uzytkownik "CountScubula" <me@scantek.hotmail.com> napisal w wiadomosci
news:Zx******************@newssvr25.news.prodigy.c om...
"Chung Leong" <ch***********@hotmail.com> wrote in message
news:NJ********************@comcast.com...
I wonder. According to the PHP manual, flush() is supposed to flush the
server's buffer as well. Presumably the function wouldn't return until it has received an acknowledgement for the last packet sent.

I tried adding ob_start("ob_gzhandler") to the beginning of the file. The measured speed increased nearly ten-fold. So I don't think it's testing the
execution speed.

Hmm, here is an idea, havent done any code, I am going to sleep, diving in
the morning.

what if you were to send a header with a timestamp:

fist call to page:
Location:
http://www.blablabla.com/test.php?action=loop&step=1&ts[1]=microtime

next call to page
Location:

http://www.blablabla.com/test.php?action=loop&step=2&ts[1]=microtime&ts[2]=m icrotime

loop a couple times of times, average out the time stamps for an average
page redirct.

this will be used a reference to delays, overhead etc...

then do this header
Location: http://www.blablabla.com/test.php?ac...avg=_avg_stamp

then for that page, send a lot of header data:
for ($i=0; $i < 100; $i++)
{
$head = "X-SpeedTest: --- speed test $i---";

$headerSize += strlen($head) + 2;
header($head);
}

header("Location:
http://www.blablabla.com/test.php?ac...=mictotime&ds= $headerSize
then the last call to the page:

$timeElapsed = (microtime() - $_GET['ts']) - $_GET['avg'];
$dataSize = $_GET['ds'];

hmm, then I think we would have a size of data sent, and time to send?

just a thought.....What do you think?

--
Mike Bradley
http://www.gzentools.com -- free online php tools

Jul 17 '05 #8
Ok, now try it at:

http://www.gzentools.com/test/speedtest.php

I think it may be off by a factor of 9 to 10, I arrive at this nubmer by
doing a local test, and it shows my DL speed as 5 Mbit/s, and when I do a
ftp download of a large file from the same server, I get about 51 Mbit/s

let me know what everyone thinks, I think we can make this happen!

--
Mike Bradley
http://www.gzentools.com -- free online php tools

"Chung Leong" <ch***********@hotmail.com> wrote in message
news:Ko********************@comcast.com...
Hmmm, using the header might be a better idea than sending the test bytes as HTML comment, as it seems the browser would save the comment tags into the
DOM (thus eat up memory). A bit cleaner too to redirect to a separate page.
Tried your page. It's reporting that my 3 mbit connection is capable of
downloading 1.8 k per second. Perhaps a larger amount of test data is
needed?


Jul 17 '05 #9
On Mon, 19 Jan 2004 23:30:16 GMT, "CountScubula"
<me@scantek.hotmail.com> brought forth from the murky depths:
Ok, now try it at:

http://www.gzentools.com/test/speedtest.php


I get "too many" redirection errors with NN7, Mike.

"Your line speed is around 11.788 Mbit/s" for Stargate
sat modem via IE6.

-
Every day above ground is a Good Day(tm).
-----------
http://diversify.com Website Application Programming
Jul 17 '05 #10
"Larry Jaques" <novalidaddress@di\/ersify.com> wrote in message
news:n2********************************@4ax.com...
On Mon, 19 Jan 2004 23:30:16 GMT, "CountScubula"
<me@scantek.hotmail.com> brought forth from the murky depths:
Ok, now try it at:

http://www.gzentools.com/test/speedtest.php


I get "too many" redirection errors with NN7, Mike.

"Your line speed is around 11.788 Mbit/s" for Stargate
sat modem via IE6.

-
Every day above ground is a Good Day(tm).
-----------
http://diversify.com Website Application Programming


OK, I changed the redirects to a lower number, how is it now?

btw, was 11.788 to high or too low?

http://www.gzentools.com/test/speedtest.php

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #11
On Wed, 21 Jan 2004 02:44:03 GMT, "CountScubula"
<me@scantek.hotmail.com> brought forth from the murky depths:
OK, I changed the redirects to a lower number, how is it now?
NN works now: Your line speed is around 933.794 Kbit/s
Your line speed is around 1.030 Mbit/s
Your line speed is around 7.401 Mbit/s
Your line speed is around 1.062 Mbit/s
IE: Your line speed is around 2.025 Mbit/s
Your line speed is around 447.926 Kbit/s
Your line speed is around 2.340 Mbit/s
Your line speed is around 754.559 Kbit/s
btw, was 11.788 to high or too low?


Good question. Satellites connections are iffy. Sometimes it
takes half an hour to upload 40 files for a site where it
would have taken 5 minutes via my 56k modem. Sometimes I get
2MB download speeds, other times 7MB speeds. The variations
in your program are probably due to the sat latencies.

Are others with true hardwired connections getting more closely
matched results, or widely varying results like mine?
----------------------------------------------------------------
"Let's sing praise to Aphrodite || www.diversify.com
She may seem a little flighty, || Full Service Websites
but she wears a green gauze nighty, || PHP Applications
And she's good enough for me." || SQL Database Development
Jul 17 '05 #12
"Larry Jaques" <novalidaddress@di\/ersify.com> wrote in message
news:ia********************************@4ax.com... > On Wed, 21 Jan 2004
02:44:03 GMT, > >btw, was 11.788 to high or too low?

Good question. Satellites connections are iffy. Sometimes it
takes half an hour to upload 40 files for a site where it
would have taken 5 minutes via my 56k modem. Sometimes I get
2MB download speeds, other times 7MB speeds. The variations
in your program are probably due to the sat latencies.

Are others with true hardwired connections getting more closely
matched results, or widely varying results like mine?
----------------------------------------------------------------
"Let's sing praise to Aphrodite || www.diversify.com

Hmm, I do not know, c'mon people post a little, please.

Btw, I did an ftp download localy, and tweeked script to match that. I
know, rudimentry baseline.
--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #13
k so i know that this is pretty old but if i were you i would look into using javascript and implement ajax(to be able to load a page behind the scenes) my theory behiond this is you shoul dbe able to open a page in the background then test to see how fast it opened(which your able to do with the readystate of an XMLHttpRequestObject)

I dunno i havent actually tried and it sjust an idea im tossing out there. because the way it seems you gusy are oging about it now is your testing the servers speed(how fast the server can compile your page) because the filesize of a page changes (for example in forums when more posts are added)

To branch off of the Ajax idea, heres how i think you could go about it:

at the end of your php script set $_SESSION["microtime_1"]=microtime(); then flush out your html

then load an image (in the HTML document)(make the file bigger in size) and say <img onLoad="runTimeTest()">

in run test run an XMLHttpRequest that opens another php page behind the scenes to set $_SESSION["microtime_2"]=microtime();

and it will also say something like echo"speed = " . $approximateFileSize/($_SESSION["microtime_2"] - $_SESSION["microtime_1"] );

$approximateFileSize = (this will be the file size of the two pages and the image added togethor)

anyways, i knwo this isnt really that clear and i probobly jumped around alot but i think this might work fo ryou. anyways hope someonee will give this a try(im too lazy lol) that is of course if anyone else is even interested still
Jun 28 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Jordanakins | last post by:
Usenet, I am currently working on my website and am needing to detect the connection speed of the client. I would like to do this in PHP and not use any other languages. This makes it a bit more...
0
by: Giovanni | last post by:
Hi, I am using VS 2005 - BETA 2. I'd like to use My.Computer.Network.IsAvailable to detect whether an internet connection is available. Is this the best "new" way of doing things or does the...
5
by: Tom Rahav | last post by:
Hello, How can I create an application/win-service in .NET that runs in the background and detects automatically when the computer connects to the internet? I want to have a program that runs...
2
by: shalin123 | last post by:
The problem is with the Internet speed in our house. we have a 10 Mbps connection which is used by around 10 people. When anyone used to download stuff using torrents the internet speed used to...
4
by: OgaW | last post by:
Hey somebody, Is there any way to increase internet speed at 512kbps for download, 256 for upload other than pay ISP more money or adding more memory? Like change certain registry setting or...
6
by: Jassim Rahma | last post by:
I want to detect the internet speed using C# to show the user on what speed he's connecting to internet?
5
by: Ke Tao | last post by:
HI All, Is there anybody have an idea of how to detect internet is reachable ? At present , I'm using ping to detect internet is reachable , but it's maybe a bad idea , some firewall of router...
3
by: mayflower | last post by:
Hi guys, Please help me in retrieving(CODE)for the bandwidth speed of internet connection in Asp.net(Csharp code). Thank you, Kranthikiran
2
by: pavanip | last post by:
Hi, I have an application like Optimize System Performance by using Memory speed, cpu speed and Disk speed. How to optimize memory speed,disk optimization and CPU optimization. Please provide me...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.