Fixed missing reuse of existing http connections which are kept-alive by remote servers (e.g. dedimania).

This commit is contained in:
Sebastian Büttner
2017-05-21 17:52:56 +02:00
parent 8241abdbf2
commit 2ec6fdbed9
2 changed files with 40 additions and 22 deletions

View File

@ -33,18 +33,6 @@ class Request extends EventDispatcher implements RequestInterface
$this->ch = curl_init();
}
/**
* Closes cURL resource and frees the memory.
* It is neccessary when you make a lot of requests
* and you want to avoid fill up the memory.
*/
public function __destruct()
{
if (isset($this->ch)) {
curl_close($this->ch);
}
}
/**
* Get the cURL\Options instance
* Creates empty one if does not exist
@ -61,7 +49,7 @@ class Request extends EventDispatcher implements RequestInterface
/**
* Sets Options
*
*
* @param Options $options Options
* @return void
*/
@ -69,6 +57,17 @@ class Request extends EventDispatcher implements RequestInterface
{
$this->options = $options;
}
/**
* Closes cURL resource and frees the memory.
* It is neccessary when you make a lot of requests
* and you want to avoid fill up the memory.
*/
public function __destruct() {
if (isset($this->ch)) {
curl_close($this->ch);
}
}
/**
* Returns cURL raw resource
@ -116,6 +115,20 @@ class Request extends EventDispatcher implements RequestInterface
return $response;
}
/**
* Binds the request to a given RequestQueue.
*
* @param \cURL\RequestsQueue $requestsQueue
* @throws \cURL\Exception
*/
public function attachTo(RequestsQueue $requestsQueue) {
if (isset($this->queue)) {
throw new Exception('Already bound to a RequestQueue.');
}
$this->queue = $requestsQueue;
$this->queue->attach($this);
}
/**
* Creates new RequestsQueue with single Request attached to it
* and calls RequestsQueue::socketPerform() method.