Added progress
This commit is contained in:
@@ -10,6 +10,8 @@ class HTTPRequest {
|
||||
public $connect_timeout = 2;
|
||||
public $transfer_timeout = 300;
|
||||
|
||||
public $callback = null;
|
||||
|
||||
public $ch = null;
|
||||
|
||||
public function __construct() {
|
||||
@@ -29,6 +31,11 @@ class HTTPRequest {
|
||||
curl_setopt($this->ch, CURLOPT_HEADER, true);
|
||||
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
|
||||
if ($this->callback) {
|
||||
curl_setopt($this->ch, CURLOPT_XFERINFOFUNCTION, $this->callback);
|
||||
curl_setopt($this->ch, CURLOPT_NOPROGRESS, false);
|
||||
}
|
||||
|
||||
$this->status = 0;
|
||||
$response = curl_exec($this->ch);
|
||||
|
||||
@@ -78,6 +85,11 @@ class HTTPRequest {
|
||||
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $data);
|
||||
|
||||
if ($this->callback) {
|
||||
curl_setopt($this->ch, CURLOPT_XFERINFOFUNCTION, $this->callback);
|
||||
curl_setopt($this->ch, CURLOPT_NOPROGRESS, false);
|
||||
}
|
||||
|
||||
$this->status = 0;
|
||||
|
||||
$response = curl_exec($this->ch);
|
||||
@@ -130,6 +142,11 @@ class HTTPRequest {
|
||||
curl_setopt($this->ch, CURLOPT_INFILE, $fh);
|
||||
curl_setopt($this->ch, CURLOPT_INFILESIZE, filesize($file));
|
||||
|
||||
if ($this->callback) {
|
||||
curl_setopt($this->ch, CURLOPT_XFERINFOFUNCTION, $this->callback);
|
||||
curl_setopt($this->ch, CURLOPT_NOPROGRESS, false);
|
||||
}
|
||||
|
||||
$this->status = 0;
|
||||
|
||||
$response = curl_exec($this->ch);
|
||||
@@ -161,4 +178,8 @@ class HTTPRequest {
|
||||
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
public function setCallback(Callable $callback) {
|
||||
$this->callback = $callback;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user