|
|
|
@ -1,6 +1,36 @@ |
|
|
|
<?php |
|
|
|
|
|
|
|
class Stream { |
|
|
|
public $_id; |
|
|
|
public $timestamp; |
|
|
|
public $premURL; |
|
|
|
public $filename; |
|
|
|
public $cstate; |
|
|
|
public $url; |
|
|
|
public $ip; |
|
|
|
|
|
|
|
function __construct($url, $premURL, $filename, $ip) |
|
|
|
{ |
|
|
|
$this->_id = new MongoId(); |
|
|
|
$this->timestamp = time(); |
|
|
|
$this->premURL = $premURL; |
|
|
|
$this->filename = $filename; |
|
|
|
$this->cstate = 'begin'; |
|
|
|
$this->url = $url; |
|
|
|
$this->ip = $ip; |
|
|
|
|
|
|
|
$db = DbMongo::get(); |
|
|
|
$coll = $db->stream; |
|
|
|
$coll->insert([ |
|
|
|
'_id' => $this->_id, |
|
|
|
'timestamp' => $this->timestamp, |
|
|
|
'ip' => $this->ip, |
|
|
|
'url' => $this->url, |
|
|
|
'cstate' => $this->cstate, |
|
|
|
'filename' => $this->filename |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Telecharge depuis $url vers $out. |
|
|
|
* |
|
|
|
@ -8,10 +38,11 @@ class Stream { |
|
|
|
* |
|
|
|
* @return array Informations sur le transfert |
|
|
|
*/ |
|
|
|
static function get($url, $filename) { |
|
|
|
function get() |
|
|
|
{ |
|
|
|
set_time_limit(0); |
|
|
|
|
|
|
|
$ch = curl_init($url); |
|
|
|
$ch = curl_init($this->premURL); |
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD'); |
|
|
|
curl_setopt($ch, CURLOPT_HEADER, true); |
|
|
|
@ -20,15 +51,51 @@ class Stream { |
|
|
|
$res = curl_exec($ch); |
|
|
|
curl_close($ch); |
|
|
|
|
|
|
|
if (!preg_match('/Content-Disposition: attachment; filename=/', $res)) { |
|
|
|
$res .= "Content-Disposition: attachment; filename=\"".$this->filename."\"; filename*=UTF-8''".$this->filename."\n"; |
|
|
|
} |
|
|
|
|
|
|
|
foreach(explode("\n", $res) as $headerLine) { |
|
|
|
header($headerLine); |
|
|
|
} |
|
|
|
|
|
|
|
$ch = curl_init($url); |
|
|
|
$ch = curl_init($this->premURL); |
|
|
|
curl_setopt ($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); |
|
|
|
curl_exec($ch); |
|
|
|
$retour = curl_getinfo($ch); |
|
|
|
curl_close($ch); |
|
|
|
return $retour; |
|
|
|
|
|
|
|
$this->cstate = 'finished'; |
|
|
|
$db = DbMongo::get(); |
|
|
|
$coll = $db->stream; |
|
|
|
$dbRet = $coll->update( |
|
|
|
['_id' => $this->_id], |
|
|
|
['$set' => ['cstate' => $this->cstate]] |
|
|
|
); |
|
|
|
|
|
|
|
$this->addEvent([ |
|
|
|
'timestamp' => time(), |
|
|
|
'state' => $this->cstate, |
|
|
|
'curlinfo' => [ |
|
|
|
'http_code' => $retour['http_code'], |
|
|
|
'total_time' => $retour['total_time'], |
|
|
|
'namelookup_time' => $retour['namelookup_time'], |
|
|
|
'connect_time' => $retour['connect_time'], |
|
|
|
'pretransfer_time' => $retour['pretransfer_time'], |
|
|
|
'size_download' => $retour['size_download'], |
|
|
|
'speed_download' => $retour['speed_download'], |
|
|
|
'starttransfer_time' => $retour['starttransfer_time'] |
|
|
|
] |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
private function addEvent($event) |
|
|
|
{ |
|
|
|
$db = DbMongo::get(); |
|
|
|
$coll = $db->stream; |
|
|
|
$dbRet = $coll->update( |
|
|
|
['_id' => $this->_id], |
|
|
|
['$push' => ['event' => $event]] |
|
|
|
); |
|
|
|
} |
|
|
|
} |