472,122 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Detect connection speed

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 complicated. I know
it is possiable to do this in PHP but I can't think of how.

All I need to figure out is if they are on dial up or not. It doesn't
have to be 100% accurate but at least 50% accurate. Any help is greatly
appreciated.

Jordan

Jul 17 '05 #1
13 7319
In article <11**********************@f14g2000cwb.googlegroups .com>,
Jo*********@gmail.com wrote:
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 complicated. I know
it is possiable to do this in PHP but I can't think of how.

All I need to figure out is if they are on dial up or not. It doesn't
have to be 100% accurate but at least 50% accurate. Any help is greatly
appreciated.


Unless you setup some sort of client/server program where the client can
be downloaded to the client browser, run where it connects to the
server, then disconnects, I don't see a way to do this with PHP. Java,
yes. But not PHP.

--
DeeDee, don't press that button! DeeDee! NO! Dee...

Jul 17 '05 #2
If it doesn't have to be 100% accurate, why not just ask the user if
they're on broadband or dialup?

Jo*********@gmail.com wrote in news:1112656179.236197.282160
@f14g2000cwb.googlegroups.com:
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 complicated. I know
it is possiable to do this in PHP but I can't think of how.

All I need to figure out is if they are on dial up or not. It doesn't
have to be 100% accurate but at least 50% accurate. Any help is greatly
appreciated.

Jordan


Jul 17 '05 #3
Hi there,

Have you thought of javascript?

<script type="text/javascript">
counter = 0;
modemNeedsThisManyMiliseconds = 700;

tempImageOf100Kbs = new Image();
tempImageOf100Kbs.onload = function() { window.clearInterval(
milisecondCounter ); ( counter < modemNeedsThisManyMiliseconds ) ?
window.location.href = "broadband.html" : window.location.href =
"modem.html"}
milisecondCounter = window.setInterval( "counter++", 1 );
tempImageOf100Kbs.src = "http://www.yoursite.com/image.jpg";
</script>

The long line does all the job, and apart from looking ugly it works.
Of course you'll need to figure out the value of the
modemNeedsThisManyMiliseconds variable...

Also you may need to put some variable string in the image
(image.jpg?code=kdmkdfmsfsd) so that browser doesn't use cache!

I hope I gave you a hint in solving your problems...

- Evanescent Lurker -

Jul 17 '05 #4
ev***************@gmail.com napisa³:
Hi there,

Have you thought of javascript?

<script type="text/javascript">
counter = 0;
modemNeedsThisManyMiliseconds = 700;

tempImageOf100Kbs = new Image();
tempImageOf100Kbs.onload = function() { window.clearInterval(
milisecondCounter ); ( counter < modemNeedsThisManyMiliseconds ) ?
window.location.href = "broadband.html" : window.location.href =
"modem.html"}
milisecondCounter = window.setInterval( "counter++", 1 );
tempImageOf100Kbs.src = "http://www.yoursite.com/image.jpg";
</script>

The long line does all the job, and apart from looking ugly it works.
Of course you'll need to figure out the value of the
modemNeedsThisManyMiliseconds variable...

Also you may need to put some variable string in the image
(image.jpg?code=kdmkdfmsfsd) so that browser doesn't use cache!


And instead of loading broadand.html or modem.html you could just make a
form on the page
<FORM name='connform' method='post' blahblahblah>
<INPUT type='hidden' name='connection' value=''>
</FORM>

and

[pseudo-code]
document.forms.connform.connection='broadband'
(or document.forms.connform.connection='modem')
document.forms.connform.submit()
[/pseudo-code]

this way you can have the info on a single page.

Cheers
Mike
Jul 17 '05 #5
ev***************@gmail.com wrote:
Hi there,

Have you thought of javascript?

<script type="text/javascript">
counter = 0;
modemNeedsThisManyMiliseconds = 700;

tempImageOf100Kbs = new Image();
tempImageOf100Kbs.onload = function() { window.clearInterval(
milisecondCounter ); ( counter < modemNeedsThisManyMiliseconds ) ?
window.location.href = "broadband.html" : window.location.href =
"modem.html"}
milisecondCounter = window.setInterval( "counter++", 1 );
tempImageOf100Kbs.src = "http://www.yoursite.com/image.jpg";
</script>


Nice function! :-)
One 'but':
Be sure to run this function AFTER the page loaded, otherwise all other kind
of downloads can interfere with the speed,

Regards,
Erwin Moller

Jul 17 '05 #6
Or even simpler, he can replace:

window.location.href = "broadband.html" : window.location.href =
"modem.html"

with

window.location.href += "?speed=broadband" : window.location.href +=
"?speed=modem"

? can be replaced with & if needed... and fetch them with $_GET in php
:)

Also you must consider what Erwin Moller wrote... I've thought of it as
an empty page which redirects, hence only my code would be loaded, but
if you bundle it with everything else there is a problem...

Jul 17 '05 #7
ev***************@gmail.com (ev***************@gmail.com) wrote:
: Hi there,

: Have you thought of javascript?

: <script type="text/javascript">
: counter = 0;
: modemNeedsThisManyMiliseconds = 700;

: tempImageOf100Kbs = new Image();
: tempImageOf100Kbs.onload = function() { window.clearInterval(
: milisecondCounter ); ( counter < modemNeedsThisManyMiliseconds ) ?
: window.location.href = "broadband.html" : window.location.href =
: "modem.html"}
: milisecondCounter = window.setInterval( "counter++", 1 );
: tempImageOf100Kbs.src = "http://www.yoursite.com/image.jpg";
: </script>

: The long line does all the job, and apart from looking ugly it works.
: Of course you'll need to figure out the value of the
: modemNeedsThisManyMiliseconds variable...

I wonder how long it takes a 14.4 modem to download the 100Kbs image used
to test the speed of the connection.
--

This space not for rent.
Jul 17 '05 #8
Malcolm Dew-Jones napisa³:
ev***************@gmail.com (ev***************@gmail.com) wrote:
: Hi there,

: Have you thought of javascript?

: <script type="text/javascript">
: counter = 0;
: modemNeedsThisManyMiliseconds = 700;

: tempImageOf100Kbs = new Image();
: tempImageOf100Kbs.onload = function() {
: window.clearInterval(
: milisecondCounter ); ( counter < modemNeedsThisManyMiliseconds ) ?
: window.location.href = "broadband.html" : window.location.href =
: "modem.html"}
: milisecondCounter = window.setInterval( "counter++", 1 );
: tempImageOf100Kbs.src = "http://www.yoursite.com/image.jpg";
: </script>

: The long line does all the job, and apart from looking ugly it works.
: Of course you'll need to figure out the value of the
: modemNeedsThisManyMiliseconds variable...

I wonder how long it takes a 14.4 modem to download the 100Kbs image
used to test the speed of the connection.

Hmmmm... I guess you could always try and test it. :)
A 14.4 modem downloads 14.4 Kb per second, that means ~1.6 KBps, which
gives us 100 / 1.5 (not 1.6 - let's assume some overhead) = ~67s.
But test it anyway. :)

Cheers
Mike
Jul 17 '05 #9
=?ISO-8859-2?Q?Micha=B3_Wo=BCniak?= (mikiwoz_remove_this@yahoo_remove_this.co.uk) wrote:
: Malcolm Dew-Jones napisa³:

: > ev***************@gmail.com (ev***************@gmail.com) wrote:
: > : Hi there,
: >
: > : Have you thought of javascript?
: >
: > : <script type="text/javascript">
: > : counter = 0;
: > : modemNeedsThisManyMiliseconds = 700;
: >
: > : tempImageOf100Kbs = new Image();
: > : tempImageOf100Kbs.onload = function() {
: > : window.clearInterval(
: > : milisecondCounter ); ( counter < modemNeedsThisManyMiliseconds ) ?
: > : window.location.href = "broadband.html" : window.location.href =
: > : "modem.html"}
: > : milisecondCounter = window.setInterval( "counter++", 1 );
: > : tempImageOf100Kbs.src = "http://www.yoursite.com/image.jpg";
: > : </script>
: >
: > : The long line does all the job, and apart from looking ugly it works.
: > : Of course you'll need to figure out the value of the
: > : modemNeedsThisManyMiliseconds variable...
: >
: > I wonder how long it takes a 14.4 modem to download the 100Kbs image
: > used to test the speed of the connection.
: >
: Hmmmm... I guess you could always try and test it. :)

Oh dear do I have to?

: A 14.4 modem downloads 14.4 Kb per second, that means ~1.6 KBps, which
: gives us 100 / 1.5 (not 1.6 - let's assume some overhead) = ~67s.
: But test it anyway. :)

Oh look, I don't have to test it because some nice person has just made a
very reasonable looking ball park estimate - it could take around a
minute.

A 56 K modem might therefore take about 15 seconds (very rough estimate).

Actually you do need to test it because part of the modem's speed comes
from data conmpression, which works less well on pre-compressed data (i.e.
jpeg images), so the speed could be slower than estimated.

(And of course you should test it anyway - the above is just to check
whether the approach is reasonable enough to be worth testing.)

Personally I preferred the suggestion to ask the user for their
preferences. Imagine if everybody's home page started testing the
connection speed using this technique.

In some settings the javascript might be very useful, so this is not meant
to sound derogatory in any way, just things to think about before you use
it.
--

This space not for rent.
Jul 17 '05 #10
You can always use smaller image but the problem is that if the image
is too small, you won't get enough diffference, and if it is too large
(and 100kb IS) then the user will walk away to other URL... This is not
an efficient way of doing it. As far as I know there is no efficent
way. I just prvided posible solution that I have never used...

Or to put it another way, I posted this so we could brain storm my idea
and help someone along the way :) This code was never tested and should
never be put on the web in a copy-paste fashion. Use your had and then
use this code :)

Anyway, you can always put "Testing your newtwork speed... Please wait"
:-)

- Evanescent Lurker -

Jul 17 '05 #11
ev***************@gmail.com (ev***************@gmail.com) wrote:
: You can always use smaller image but the problem is that if the image
: is too small, you won't get enough diffference, and if it is too large
: (and 100kb IS) then the user will walk away to other URL... This is not
: an efficient way of doing it. As far as I know there is no efficent
: way. I just prvided posible solution that I have never used...

: Or to put it another way, I posted this so we could brain storm my idea
: and help someone along the way :) This code was never tested and should
: never be put on the web in a copy-paste fashion. Use your had and then
: use this code :)

: Anyway, you can always put "Testing your newtwork speed... Please wait"
: :-)

The microsoft client update software that runs on lans (can't think what
it's called right now) uses a similar test before deciding how best to
proceded.

If you had a specific client base where most people are normally connected
at high speed then your idea could be a good kludge to use before trying
to do something like send large documents, or etc. so like I said, I'm not
trying to put the idea down at all.

--

This space not for rent.
Jul 17 '05 #12
It should be possible, I think, to accomplish the same thing without
using javascript ( but with still using a redirecting "testing
connection speed" gateway page ).

If, at the top of your php script, you were to store the current
microtime into a session variable...Then output several kilobytes of
random characters inside an HTML comment...Finally output a <meta
HTTP-EQUIV='Refresh' Content='0; Url=target_page.php;'> tag. Then on
the target_page.php you could read the microtime again and compare it
to what you stored in the session.

-Ramius

p.s. - The reasoning for the random characters instead of just
whitespace is because it should hopefully slow the modem down more (
less compressible ). Also, beware that if your webserver is gzip'ing
your output, this will skew your results!
ev***************@gmail.com wrote:
Hi there,

Have you thought of javascript?


Jul 17 '05 #13
>
p.s. - The reasoning for the random characters instead of just
whitespace is because it should hopefully slow the modem down more (
less compressible ). Also, beware that if your webserver is gzip'ing
your output, this will skew your results!


Yeah, and make sure that the function returning the random string is
faster than the connection. ;)

Cheers
Mike
Jul 17 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Yang Li Ke | last post: by
5 posts views Thread by chris | last post: by
12 posts views Thread by Alban Hertroys | last post: by
4 posts views Thread by Frank Meng | last post: by
13 posts views Thread by Shailesh Humbad | last post: by

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.