Test a speed test script. I don't know where the error is.

Source: Internet
Author: User
Tags netspeed
Test a speed test script. I don't know where the error is.
/* = Create a data file that will be transmitted to the user = */$ fp = fopen ("cs.txt", "w"); for ($ I = 0; $ I <1704000; $ I ++) {fwrite ($ fp, "bandwidthkh") ;}fclose ($ fp ); // = write the current network speed calculation script = function microtime_float () {list ($ usec, $ sec) = explode ("", microtime ()); return (float) $ usec + (float) $ sec) ;}$ data = file_get_contents ("cs.txt"); $ start = microtime_float (); $ fsize = filesize ("cs.txt")/1024; // filesize returns the number of bytes of the file size echo "sent to the client ". $ fsize. "KB data
"; Echo" "; $ Stop = microtime_float (); $ duration = ($ stop-$ start); echo $ duration." s
"; $ Speed = round ($ fsize/$ duration, 2); echo" Your network speed: $ speed KB/sec ";

The result is

It reaches 1 GB per second. isn't that possible?


Reply to discussion (solution)

Yes!
What you test is
$ Fsize = filesize ("cs.txt")/1024; // filesize returns the number of bytes of the file size.
Echo "send to client". $ fsize. "KB data
";
Echo" ";
The speed at which these three statements are executed is irrelevant to the speed of the network.

Microtime (true) is the float type of seconds.
No need to write the microtime_float function

In the past, when I used ajax to upload files, several GB of files were uploaded in a few seconds. Therefore, I think it is normal to use a local computer as both a server and a client.

Yes!
What you test is
$ Fsize = filesize ("cs.txt")/1024; // filesize returns the number of bytes of the file size.
Echo "send to client". $ fsize. "KB data
";
Echo" ";
The speed at which these three statements are executed is irrelevant to the speed of the network.


Why?

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.