Measuring bandwidth used using PHP.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    Measuring bandwidth used using PHP.

    I've had a good luck around for something along the lines of what i wanted, all to no avail.
    Was just wondering if anyone knew of a way to record bandwidth usage?
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Originally posted by markusn00b
    I've had a good luck around for something along the lines of what i wanted, all to no avail.
    Was just wondering if anyone knew of a way to record bandwidth usage?
    Good Question! I'm looking forward is someone gives a good reply.

    I can give you an idea though...

    When user clicks on a bandwidth checking link, send some data to the user's browser. And when the data reaches completely, tell JavaScript to send it back.
    Calculate time between start of sending and end of receiving that data.
    Divide the data size by (4 * $seconds_taken) . May be it could tell you the bandwidth.

    But what if user is downloading or uploading something along with?

    PS: Don't laugh!! :p

    Comment

    • dlite922
      Recognized Expert Top Contributor
      • Dec 2007
      • 1586

      #3
      Originally posted by hsriat
      Good Question! I'm looking forward is someone gives a good reply.

      I can give you an idea though...

      When user clicks on a bandwidth checking link, send some data to the user's browser. And when the data reaches completely, tell JavaScript to send it back.
      Calculate time between start of sending and end of receiving that data.
      Divide the data size by (4 * $seconds_taken) . May be it could tell you the bandwidth.

      But what if user is downloading or uploading something along with?

      PS: Don't laugh!! :p

      no one's laughing, i wouldn't have thought of that.....okay maybe i would have...but you went into detail.

      I say so what if he's downloading something, that's his bandwidth currently at this time he's browsing the website, display the info (quality) based on that bandwidth.

      If he comes back another time with more bandwidth he can see the better quality vido/flash/porn/etc...



      -DM

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        Originally posted by dlite922
        I say so what if he's downloading something, that's his bandwidth currently at this time he's browsing the website, display the info (quality) based on that bandwidth.
        That's what I said in the second last line.

        PS: Glad to know you didn't laugh. :D

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Originally posted by hsriat
          That's what I said in the second last line.

          PS: Glad to know you didn't laugh. :D
          I didn't laugh, either!

          Could you elaborate on:
          When user clicks on a bandwidth checking link, send some data to the user's browser. And when the data reaches completely, tell JavaScript to send it back.
          ?

          Cheers

          Comment

          • hsriat
            Recognized Expert Top Contributor
            • Jan 2008
            • 1653

            #6
            When user clicks on the link, create a hidden iframe and give src of an HTML file, something like this:[html]<html>
            <body onload="documen t.forms[0].submit()">
            <form acton="return_d ata.php" method="post">
            <input type="hidden" name="data" value="----------fake text of size say 50Kb---------" />
            </form>
            </body>
            </html>[/html]
            Since the iframe is hidden, nothing would be shown on the browser.

            When the server gets the request from a user for that file, save start time somewhere (of course corresponding to the user id or IP), and when return_data.php gets back the whole data, save the end time.

            I hope it can work, but not sure! This is just a first try. I've never done anything like this.

            Comment

            Working...