finish() public static method

Completes a cURL transaction, either returning a response promise or a rejected promise.
public static finish ( callable $handler, GuzzleHttp\Handler\EasyHandle $easy, GuzzleHttp\Handler\CurlFactoryInterface $factory ) : GuzzleHttp\Promise\PromiseInterface
$handler callable
$easy GuzzleHttp\Handler\EasyHandle
$factory GuzzleHttp\Handler\CurlFactoryInterface Dictates how the handle is released
return GuzzleHttp\Promise\PromiseInterface
Example #1
0
 public function __invoke(RequestInterface $request, array $options)
 {
     if (isset($options[RequestOptions::DELAY])) {
         usleep($options[RequestOptions::DELAY] * 1000);
     }
     $easy = $this->factory->create($request, $options);
     curl_exec($easy->handle);
     $easy->errno = curl_errno($easy->handle);
     return CurlFactory::finish($this, $easy, $this->factory);
 }
Example #2
0
 private function processMessages()
 {
     while ($done = curl_multi_info_read($this->_mh)) {
         $id = (int) $done['handle'];
         curl_multi_remove_handle($this->_mh, $done['handle']);
         if (!isset($this->handles[$id])) {
             // Probably was cancelled.
             continue;
         }
         $entry = $this->handles[$id];
         unset($this->handles[$id], $this->delays[$id]);
         $entry['easy']->errno = $done['result'];
         $entry['deferred']->resolve(CurlFactory::finish($this, $entry['easy'], $this->factory));
     }
 }
 /**
  * @expectedException \GuzzleHttp\Exception\RequestException
  * @expectedExceptionMessage The cURL request was retried 3 times
  */
 public function testFailsWhenRetryMoreThanThreeTimes()
 {
     $factory = new Handler\CurlFactory(1);
     $call = 0;
     $fn = function ($request, $options) use(&$mock, &$call, $factory) {
         $call++;
         $easy = $factory->create($request, $options);
         return Handler\CurlFactory::finish($mock, $easy, $factory);
     };
     $mock = new Handler\MockHandler([$fn, $fn, $fn]);
     $p = $mock(new Psr7\Request('PUT', Server::$url, [], 'test'), []);
     $p->wait(false);
     $this->assertEquals(3, $call);
     $p->wait(true);
 }
Example #4
0
 private function processHttpMessages()
 {
     $clean = true;
     while ($done = curl_multi_info_read($this->multiHandle)) {
         $id = (int) $done['handle'];
         curl_multi_remove_handle($this->multiHandle, $done['handle']);
         if (!isset($this->httpHandles[$id])) {
             // Probably was cancelled.
             continue;
         }
         $entry = $this->httpHandles[$id];
         unset($this->httpHandles[$id], $this->delays[$id]);
         $entry['easy']->errno = $done['result'];
         /** @var Promise $deferred */
         $deferred = $entry['promise'];
         /** @var CurlFactoryInterface $factory */
         $factory = $this->factory[self::TYPE_HTTP];
         $deferred->resolve(CurlFactory::finish($this, $entry['easy'], $factory));
         $clean = false;
     }
     if (!$clean) {
         \GuzzleHttp\Promise\queue()->run();
         return true;
     }
     return false;
 }