By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,596 Members | 3,653 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,596 IT Pros & Developers. It's quick & easy.

Detect connection speed

P: n/a
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
Share this Question
Share on Google+
13 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
=?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

P: n/a
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

P: n/a
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

P: n/a
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: n/a
>
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.