Commit ca6e427e authored by Francesco Iannuzzelli's avatar Francesco Iannuzzelli

Add download custom timeout

parent 36d40066
......@@ -50,6 +50,8 @@ class Cache
* @var FileManager */
private $fm;
public $timeout;
/**
* Initialize local properties
*
......@@ -59,6 +61,7 @@ class Cache
$this->fm = new FileManager;
$conf = new Configuration();
$this->ttl = $conf->Get("cache_ttl");
$this->timeout = 0;
}
/**
......@@ -257,7 +260,10 @@ class Cache
}
break;
case "webpage":
$this->fm->Download($id,$filename);
$statusCode = $this->fm->Download($id,$filename,false,$this->timeout);
if($statusCode==0) {
$this->Delete('webpage',$id);
}
break;
case "widget_feature":
include_once(SERVER_ROOT."/../classes/layout.php");
......
......@@ -497,12 +497,15 @@ class FileManager
* @param boolean $is_critical Whether this operation is critical or not. If critical, a critical error is raised which will stop script execution
* @return integer HTTP code
*/
public function DownLoad($from,$to,$is_critical=false)
public function DownLoad($from,$to,$is_critical=false,$timeout=0)
{
$ch = curl_init($from);
$fp = fopen("$this->path/$to", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
if($timeout>0) {
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout );
}
if(!$this->safe_mode && !$this->open_basedir)
{
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
......@@ -515,7 +518,6 @@ class FileManager
{
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}
// timeout ?
curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_errno($ch)>0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment