: This article mainly introduces how Nginx supports multi-thread download and resumable Upload. For more information about PHP tutorials, see. RFC2616 defines the range protocol, which provides a rule that allows the client to download only a part of the complete file in another request, in this way, the client can download a file while enabling multithreading. each thread only downloads a part of the file and finally combines it into a complete file. range also supports resumable Upload, as long as the client records the offset of some downloaded files, you can ask the server to send the content after the file is sent from the breakpoint.
Nginx supports the range protocol very well, because the range protocol mainly adds some HTTP header processing flows and offset processing when sending files. Nginx has designed an HTTP filter module. each request can be processed by many HTTP filter modules. the http_range_header_filter module is used to process the range part of the HTTP request header. it will parse the range header in the client request, finally, we will inform you that the ngx_http_range_body_filter_module module will be called when an HTTP response package body is sent. This module will modify the file_pos and file_last members of the ngx_buf_t buffer pointing to the file according to the range protocol, in this way, only part of the file is sent to the client.
In fact, it is very easy to support the range protocol. you only need to set the allow_ranges variable of ngx_http_request_t to 1 before sending, and the subsequent steps will be completed by the HTTP Framework. Eg:
R-> allow_ranges = 1;
In this way, we support multi-threaded download and resumable Upload.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above describes how Nginx supports multi-thread download and resumable data transfer for users, including some content. I hope my friends who are interested in PHP tutorials will be helpful.