Php downloads large files and saves them on the server

such as the title.
cannot use set_time_limit (0) because online projects will not allow you to execute indefinitely

all I can think of now is to use curl

curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($ch ,$str){});

read a small portion at a time and then write to the file.

I don"t know if there is a better way. I hope you can give me some advice.

Php
Feb.07,2022

online items can set page timeouts so that


can be run indefinitely.

the breakpoint can be used to continue the transmission.

the prerequisite is that the server supports breakpoint continuation. This only depends on whether the response header returned by the server contains the following header:
Accept-Ranges: bytes

.

as long as you have this header, it means that the other party supports the continuation of the breakpoint.

this allows you to add the following header, to the request header for each request to specify the range of data to be read:

Range: bytes=1024-2047 requests data from 1024 bytes to 2047 bytes

Range: bytes=2048- request content from 2048 bytes to the last byte

and so on.

Menu