有些日子我有从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');
?>
此网址文件大小为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'.
例如:
Function download_url_one
(已下载128.02 MB)
Function download_url_two
- &gt; (已下载122.54 MB)
Function download_url_three
- &gt; (128.02 MB下载)Function download_url_four
- &gt; (124.45 MB下载)请帮帮我,如何解决这个问题?
答案 0 :(得分:0)
这是来自服务器的问题,我再次与支持服务器通信,以便在服务器上增加time limit
并解决。默认时间限制为120秒,当增加到400秒时,问题解决了。我认为当我在PHP Select Version
上设置任何更改时,此更改是其他设置的上限。 (more info)
感谢@Halcyon。