Help View Segment Code

Source: Internet
Author: User
Help you look at the snippet code
PHP Code
  
           $filename = ' test.txt ';    $data = file_get_contents ($filename);    $fsize = FileSize ($filename)/1024x768;        $start = time ();    echo "
  
    ";    $stop = time ();        $duration = $stop-$start;    $speed = Round ($fsize/$duration, 2);        echo "Your network speed: $speed kb/s";

The book said that this code can calculate network bandwidth, I tried to find no, $start and $stop are equal. Think about it, $duration calculate the time that the PHP engine parses the Echo statement, not the time the user receives $data. Think again, if you want to calculate the bandwidth, you have to calculate the user gets the HTML file time, but that is after the PHP parsing is done, it is not possible to use PHP to calculate the user bandwidth is not the case?? Please correct me, ask for the realization of calculating user's bandwidth

------Solution--------------------
Put $stop = time (); Move to the front
Your code detects the speed at which the file is read

Continue to
$filename assignment to a remote file name
FileSize ($filename) to strlen ($data)
Your code detects the bandwidth of your server.

Only PHP is not able to detect user bandwidth
There must be client collaboration, roughly as follows
The client issues a test request (onsubmit) while recording and issuing the time the request occurred
PHP outputs a fixed-size content after a request is received and logs the time that the client sent (thus calculating the client's upstream time)
In the client's onload event, the current time is given to PHP again
PHP gets down time after deduction of upstream time
And then.....
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.