public function testReleasesAdditionalEasyHandles()
 {
     Server::flush();
     Server::enqueue(["HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n", "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n", "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n", "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"]);
     $a = new CurlAdapter(new MessageFactory(), ['max_handles' => 2]);
     $client = new Client(['base_url' => Server::$url, 'adapter' => $a]);
     $request = $client->createRequest('GET', '/', ['events' => ['headers' => function (HeadersEvent $e) use($client) {
         $client->get('/', ['events' => ['headers' => function (HeadersEvent $e) {
             $e->getClient()->get('/');
         }]]);
     }]]);
     $transaction = new Transaction($client, $request);
     $a->send($transaction);
     $this->assertCount(2, $this->readAttribute($a, 'handles'));
 }
Example #2
0
 /**
  * Remove a transaction and associated handle from the context
  *
  * @param TransactionInterface $transaction Transaction to remove
  *
  * @return array Returns the curl_getinfo array
  * @throws AdapterException if the transaction is not found
  */
 public function removeTransaction(TransactionInterface $transaction)
 {
     if (!isset($this->handles[$transaction])) {
         throw new AdapterException('Transaction not registered');
     }
     $handle = $this->handles[$transaction];
     $code = curl_multi_remove_handle($this->multi, $handle);
     if ($code != CURLM_OK) {
         CurlAdapter::throwMultiError($code);
     }
     $info = curl_getinfo($handle);
     curl_close($handle);
     unset($this->handles[$transaction]);
     return $info;
 }
Example #3
0
 public function testRewindsStreamOnComplete()
 {
     Server::flush();
     Server::enqueue("HTTP/1.1 200 OK\r\nFoo: bar\r\nContent-Length: 4\r\n\r\ntest");
     $t = new Transaction(new Client(), new Request('GET', Server::$url));
     $a = new CurlAdapter(new MessageFactory());
     $response = $a->send($t);
     $this->assertEquals('test', $response->getBody()->read(4));
 }