PHP 从 URL 下载(不能下载超过 123MB)

PHP download from URL (can't download over 123MB)

有些日子我在从 URL 下载时遇到问题。检查了很多方法,但我无法下载超过 123MB 的 URL 文件!

我的代码:

.htaccess

<IfModule php5_module>
   php_value allow_url_fopen On
   php_flag asp_tags Off
   php_flag display_errors Off
   php_value max_execution_time 10000
   php_value max_input_time 10000
   php_value max_input_vars 10000
   php_value memory_limit 12800M
   php_value upload_max_filesize 2000M
</IfModule>

functions.php

<?php

ini_set('memory_limit', '-1');
ini_set('upload_max_size' , '1024M' );
ini_set('post_max_size', '1024M');
ini_set('max_execution_time', '10000' );
set_time_limit (24 * 60 * 60);
//---------------------------------------------------------
function download_url_one($url , $filename)
{
    //first way
    file_put_contents($filename, fopen($url, 'r'));
}
//---------------------------------------------------------
function download_url_two($url , $filename , $post = null)
{
    //second way
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    curl_setopt($ch, CURLOPT_REFERER, "https://www.youtube.com/");
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_HEADER, 0);

    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT , 200000); 
    curl_setopt($ch, 156 , 200000);//CURLOPT_CONNECTTIMEOUT_MS
    curl_setopt($ch, CURLOPT_TIMEOUT, 200000); //timeout in seconds
    curl_setopt($ch, 155, 200000);//CURLOPT_TIMEOUT_MS

    $result = curl_exec($ch);
    curl_close($ch);
    file_put_contents($filename, $result);
}
//---------------------------------------------------------
function download_url_three($url , $filename)
{
    //third way
    exec("wget $url -O $filename");
}
//---------------------------------------------------------
function download_url_four($url , $filename)
{
    //fourth way
    file_put_contents($filename, file_get_contents($url));
}
//---------------------------------------------------------

?>

index.php

<?php
include_once('functions.php');

$url = 'https://pc.tedcdn.com/talk/podcast/2004/None/DanGilbert_2004-480p.mp4';
download_url_one($url , 'example.mp4');
//download_url_two($url , 'example.mp4');
//download_url_three($url , 'example.mp4');
//download_url_four($url , 'example.mp4');
?>

此 url 文件大小为 143.76 MB。使用每个功能进行下载后 url,仅完成约 ~123 MB 的下载。然后显示错误 500 Internal Server Error. Request Timeout. This request takes too long to process, it is timed out by the server. If it should not be timed out, please contact administrator of this web site to increase 'Connection Timeout'.

例如:

我与我的服务器支持人员进行了交谈,并对这张图片应用了相同的设置。

请帮帮我,这个问题怎么解决?

这是服务器的问题,我再次与支持服务器交谈以增加服务器 time limit 并解决了。默认时间限制为 120 秒,当增加到 400 秒时,问题就解决了。我认为当我在 PHP Select Version 上设置任何更改时,此更改高于其他设置。 () 感谢@Halcyon。