My script downloads only 2 mb. I think it is because of some sort of restriction on this server. My script resides on this server and is to download files (like pictures and movies) from the web. But movies fail; only two mb get downloaded to the server. Can I do anything about it?
views:
113answers:
6There are several problems you might be having here.
Take a close look at your php.ini file.
You want to be certain for instance that you have very large values for
max_execution_time memory_limit
you might even consider default_socket_timeout
It would help us if you included any error the script gives, or reports to syslog (or windows equivalent)
HTH, -FT
Try adding:
php_value upload_max_filesize 15M
To your .htaccess (if you're using apache at least). That is 15mb. The default is usually set to 2mb.
This has worked fine for me, but ftrotter is correct in pointing out that you may also hit time limits as well.
If your PHP is not running in safe mode you can try calling:
set_time_limit($seconds);
To change the length of time your PHP script is allowed to run. Otherwise you will have to change max_execution_time in your php.ini if you can.
Also be aware that if you're on shared hosting, some providers will kill off long running processes without warning.
You need to read files by small chunks, not the whole file at one file_get_contents call. Provide an example of how you download them. We will help to modify script to remove memory consuming parts.
This is how I do:
$filename = 'file';
$fp = fopen($filename,'w+');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $the_link);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
Also, I have changed with max_execution_time and upload_max_filesize with the .htaccess file.
Yes but you need to write the script so it can resume. This is pretty forward use CURLOPT_RANGE to continue after a first shutdown by the server.
Then call your downloading page from time to time via a cron job and use a flock around the CURL code to see if the download is still in progress or terminated.
It is very unlikely that you can download large files in one HTTP response.