Php code to limit the speed of file downloads _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Php implements code instances that limit the speed of file downloads. Sometimes you want to slow down the download speed for some purpose. for example, you want to implement the file download progress bar function. The biggest advantage of limiting the download speed is to save bandwidth and avoid downloading files for some purpose. for example, you want to implement the file download progress bar function. The biggest advantage of limiting the download speed is to save bandwidth and avoid network congestion caused by excessive instantaneous traffic.

Analysis: The above example limits the file download speed to kb/s, that is, only a KB file stream is sent to the client every second until the complete file is sent. If there is no such restriction, the file will be sent together to the client in the form of a stream. how many messages will be sent? what will happen? If the file size is 2 MB, the 2 MB data stream will be transferred at once, which may cause network congestion and interrupt script execution. this download method cannot be used in practical applications.

Technically, first add the header file and declare Content-Type as application/octet-stream. This indicates that the request will be sent as a stream and the Content-Length is declared, the file stream size is declared. The flush () function is used in the code to refresh the buffer of the php program and implement print dynamic output.

The above code can be cleverly used to display the file download progress bar on the client. if you are interested, try it.

Note: For more exciting tutorials, please pay attention to the tutorial channel for helping customers,

Bytes. The biggest advantage of limiting the download speed is to save bandwidth and avoid it...

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.