Sometimes you may want to slow down the download file for some reason, such as you would like to implement the file download progress bar function. The biggest advantage of limiting download speed is that it saves bandwidth and avoids the network jam caused by excessive instantaneous traffic.
Analysis: The above example limits file download speed to 20.5kb/s, that is, sending only 20.5kb of file streams per second to the client until the entire file is sent. If this limit is not available, then the file will be sent to the client in the form of a stream, how much will be sent, what happens? If the file size is 2m, then all of a sudden to the 2m data circulated to the past, this will likely lead to network congestion and interrupt the execution of the script, this download method can not be used in practical applications.
Technically, you first add a header file, declare Content-type as Application/octet-stream, indicate that the request will be sent as a stream, and declare content-length, which declares the file flow size. The flush () is used in the code, and the flush function is to refresh the buffer of the PHP program and realize the print dynamic output.
The above code, after clever use, can realize the client to display file download progress bar function, interested words may wish to try.
Note : Please pay attention to the triple tutorial channel for more wonderful tutorials,