Detect connection speed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jordanakins@gmail.com

    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

  • Michael Vilain

    #2
    Re: Detect connection speed

    In article <1112656179.236 197.282160@f14g 2000cwb.googleg roups.com>,
    Jordanakins@gma il.com wrote:
    [color=blue]
    > 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.[/color]

    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...



    Comment

    • Brian

      #3
      Re: Detect connection speed

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

      Jordanakins@gma il.com wrote in news:1112656179 .236197.282160
      @f14g2000cwb.go oglegroups.com:
      [color=blue]
      > 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
      >
      >[/color]

      Comment

      • evanescent.lurker@gmail.com

        #4
        Re: Detect connection speed

        Hi there,

        Have you thought of javascript?

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

        tempImageOf100K bs = new Image();
        tempImageOf100K bs.onload = function() { window.clearInt erval(
        milisecondCount er ); ( counter < modemNeedsThisM anyMiliseconds ) ?
        window.location .href = "broadband.html " : window.location .href =
        "modem.html "}
        milisecondCount er = window.setInter val( "counter++" , 1 );
        tempImageOf100K bs.src = "http://www.yoursite.co m/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
        modemNeedsThisM anyMiliseconds 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 -

        Comment

        • Micha³ Wo¼niak

          #5
          Re: Detect connection speed

          evanescent.lurk er@gmail.com napisa³:
          [color=blue]
          > Hi there,
          >
          > Have you thought of javascript?
          >
          > <script type="text/javascript">
          > counter = 0;
          > modemNeedsThisM anyMiliseconds = 700;
          >
          > tempImageOf100K bs = new Image();
          > tempImageOf100K bs.onload = function() { window.clearInt erval(
          > milisecondCount er ); ( counter < modemNeedsThisM anyMiliseconds ) ?
          > window.location .href = "broadband.html " : window.location .href =
          > "modem.html "}
          > milisecondCount er = window.setInter val( "counter++" , 1 );
          > tempImageOf100K bs.src = "http://www.yoursite.co m/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
          > modemNeedsThisM anyMiliseconds variable...
          >
          > Also you may need to put some variable string in the image
          > (image.jpg?code =kdmkdfmsfsd) so that browser doesn't use cache![/color]

          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='connectio n' value=''>
          </FORM>

          and

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

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

          Cheers
          Mike

          Comment

          • Erwin Moller

            #6
            Re: Detect connection speed

            evanescent.lurk er@gmail.com wrote:
            [color=blue]
            > Hi there,
            >
            > Have you thought of javascript?
            >
            > <script type="text/javascript">
            > counter = 0;
            > modemNeedsThisM anyMiliseconds = 700;
            >
            > tempImageOf100K bs = new Image();
            > tempImageOf100K bs.onload = function() { window.clearInt erval(
            > milisecondCount er ); ( counter < modemNeedsThisM anyMiliseconds ) ?
            > window.location .href = "broadband.html " : window.location .href =
            > "modem.html "}
            > milisecondCount er = window.setInter val( "counter++" , 1 );
            > tempImageOf100K bs.src = "http://www.yoursite.co m/image.jpg";
            > </script>[/color]

            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

            Comment

            • evanescent.lurker@gmail.com

              #7
              Re: Detect connection speed

              Or even simpler, he can replace:

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

              with

              window.location .href += "?speed=broadba nd" : window.location .href +=
              "?speed=mod em"

              ? 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...

              Comment

              • Malcolm Dew-Jones

                #8
                Re: Detect connection speed

                evanescent.lurk er@gmail.com (evanescent.lur ker@gmail.com) wrote:
                : Hi there,

                : Have you thought of javascript?

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

                : tempImageOf100K bs = new Image();
                : tempImageOf100K bs.onload = function() { window.clearInt erval(
                : milisecondCount er ); ( counter < modemNeedsThisM anyMiliseconds ) ?
                : window.location .href = "broadband.html " : window.location .href =
                : "modem.html "}
                : milisecondCount er = window.setInter val( "counter++" , 1 );
                : tempImageOf100K bs.src = "http://www.yoursite.co m/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
                : modemNeedsThisM anyMiliseconds 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.

                Comment

                • Micha³ Wo¼niak

                  #9
                  Re: Detect connection speed

                  Malcolm Dew-Jones napisa³:
                  [color=blue]
                  > evanescent.lurk er@gmail.com (evanescent.lur ker@gmail.com) wrote:
                  > : Hi there,
                  >
                  > : Have you thought of javascript?
                  >
                  > : <script type="text/javascript">
                  > : counter = 0;
                  > : modemNeedsThisM anyMiliseconds = 700;
                  >
                  > : tempImageOf100K bs = new Image();
                  > : tempImageOf100K bs.onload = function() {
                  > : window.clearInt erval(
                  > : milisecondCount er ); ( counter < modemNeedsThisM anyMiliseconds ) ?
                  > : window.location .href = "broadband.html " : window.location .href =
                  > : "modem.html "}
                  > : milisecondCount er = window.setInter val( "counter++" , 1 );
                  > : tempImageOf100K bs.src = "http://www.yoursite.co m/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
                  > : modemNeedsThisM anyMiliseconds variable...
                  >
                  > I wonder how long it takes a 14.4 modem to download the 100Kbs image
                  > used to test the speed of the connection.
                  >[/color]
                  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

                  Comment

                  • Malcolm Dew-Jones

                    #10
                    Re: Detect connection speed

                    =?ISO-8859-2?Q?Micha=B3_Wo =BCniak?= (mikiwoz_remove _this@yahoo_rem ove_this.co.uk) wrote:
                    : Malcolm Dew-Jones napisa³:

                    : > evanescent.lurk er@gmail.com (evanescent.lur ker@gmail.com) wrote:
                    : > : Hi there,
                    : >
                    : > : Have you thought of javascript?
                    : >
                    : > : <script type="text/javascript">
                    : > : counter = 0;
                    : > : modemNeedsThisM anyMiliseconds = 700;
                    : >
                    : > : tempImageOf100K bs = new Image();
                    : > : tempImageOf100K bs.onload = function() {
                    : > : window.clearInt erval(
                    : > : milisecondCount er ); ( counter < modemNeedsThisM anyMiliseconds ) ?
                    : > : window.location .href = "broadband.html " : window.location .href =
                    : > : "modem.html "}
                    : > : milisecondCount er = window.setInter val( "counter++" , 1 );
                    : > : tempImageOf100K bs.src = "http://www.yoursite.co m/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
                    : > : modemNeedsThisM anyMiliseconds 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.

                    Comment

                    • evanescent.lurker@gmail.com

                      #11
                      Re: Detect connection speed

                      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 -

                      Comment

                      • Malcolm Dew-Jones

                        #12
                        Re: Detect connection speed

                        evanescent.lurk er@gmail.com (evanescent.lur ker@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.

                        Comment

                        • Ramius

                          #13
                          Re: Detect connection speed

                          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...Final ly 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!


                          evanescent.lurk er@gmail.com wrote:[color=blue]
                          > Hi there,
                          >
                          > Have you thought of javascript?
                          >[/color]

                          Comment

                          • Micha³ Wo¼niak

                            #14
                            Re: Detect connection speed

                            >[color=blue]
                            > 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![/color]

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

                            Cheers
                            Mike

                            Comment

                            Working...