PHP长期运行脚本替代? [重复]

This question already has an answer here:

I'm trying to download a file from a remote server with file_put_contents. This script is called via ajax. The problem i'm having is the script timeout when the file is large e.g. (500mb). I get 504 Gateway Timeout - nginx

download.php $destination = "/home/mywebsite/public_html/wp-content/channels/videos/test.mp4";

    $link = "http://www.example.com/videos/movie.mp4"; //500mb
    $result = file_put_contents($destination, fopen($link, 'r'));

I'm using dedicated hosting. I've changed my php.ini and confirmed in phpinfo();

max_execution_time 7200 max_input_time 7200 max_input_vars 1000 memory_limit -1 output_buffering 4096 post_max_size 1200M upload_max_filesize 1000M

This script keeps timing out. Is there another solution how do i solve? When i check the directory the file is successfully downloaded but the page times out. So i can't return any data via ajax.

How do i solve?

</div>

You should also change nginx fcgi timeout values. PHP script continues executing but your connection between nginx and PHP timeouts.

Make download asynchronous. Like one process only fill some DB or rabbitMq with download requests and other wil cosume it (maybe cron)