Home > Backend Development > PHP Tutorial > Nginx supports users' multi-threaded downloads and breakpoint resume downloads

Nginx supports users' multi-threaded downloads and breakpoint resume downloads

WBOY
Release: 2016-07-30 13:31:24
Original
1723 people have browsed it

The range protocol is defined in the RFC2616 specification, which provides a rule that allows the client to download only a part of the complete file in one request. This supports the client to download a file while enabling multi-threading, each of which The thread only downloads a part of the file and finally combines it into a complete file. Range also supports breakpoint resumption. As long as the client records the offset of the downloaded partial file, it can ask the server to send the content after the file from the breakpoint.
Nginx supports the range protocol very well, because the range protocol mainly adds some HTTP header processing procedures and offset processing when sending files. Nginx has designed an HTTP filtering module. Each request can be processed by many HTTP filtering 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 and finally inform the user before sending the HTTP response. When the package body is generated, the ngx_http_range_body_filter_module module will be called. 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, so that only part of the content of a file can be sent to the client.
In fact, supporting the range protocol is very simple for us. We only need to set the allow_ranges variable of the ngx_http_request_t member to 1 before sending, and the rest will be completed by the HTTP framework. eg:
r->allow_ranges = 1;
In this way, we support multi-threaded downloads and resumed downloads.

Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above introduces Nginx's support for multi-threaded downloads and breakpoint resume downloads, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template