Skip to content
Browse files

MDL-14051 Changed timeout behaviour for download_file_content so curl…

… has a read timeout
  • Loading branch information...
sam_marshall committed Mar 26, 2008
1 parent 017933f commit 44e02d79abe080b739d931ab9c4e9375fc239ac9
Showing with 9 additions and 3 deletions.
  1. +9 −3 lib/filelib.php
@@ -10,10 +10,14 @@
* @param array $headers http headers, null if none
* @param array $postdata array means use POST request with given parameters
* @param bool $fullresponse return headers, responses, etc in a similar way snoopy does
* @param int $timeout connection timeout
* @param int $timeout timeout for complete download process including all file transfer
* (default 5 minutes)
* @param int $connecttimeout timeout for connection to server; this is the timeout that
* usually happens if the remote server is completely down (default 20 seconds);
* may not work when using proxy
* @return mixed false if request failed or content of the file as string if ok.
function download_file_content($url, $headers=null, $postdata=null, $fullresponse=false, $timeout=20) {
function download_file_content($url, $headers=null, $postdata=null, $fullresponse=false, $timeout=300, $connecttimeout=20) {
global $CFG;
// some extra security
@@ -43,6 +47,7 @@ function download_file_content($url, $headers=null, $postdata=null, $fullrespons
$snoopy = new Snoopy();
$snoopy->read_timeout = $timeout;
$snoopy->_fp_timeout = $connecttimeout;
$snoopy->proxy_host = $CFG->proxyhost;
$snoopy->proxy_port = $CFG->proxyport;
if (!empty($CFG->proxyuser) and !empty($CFG->proxypassword)) {
@@ -118,7 +123,8 @@ function download_file_content($url, $headers=null, $postdata=null, $fullrespons
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $connecttimeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
if (!ini_get('open_basedir') and !ini_get('safe_mode')) {
// TODO: add version test for '7.10.5'
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

0 comments on commit 44e02d7

Please sign in to comment.
You can’t perform that action at this time.