예제 #1
0
 function testQueueing()
 {
     $client = new \Guzzle\Http\Client();
     $client->getCurlMulti()->getEventDispatcher()->addSubscriber(new ConnectionLimit(2));
     $queueings = 0;
     $client->getEventDispatcher()->addListener('request.queued', function ($event) use(&$queueings) {
         $queueings++;
     });
     $dequeueings = 0;
     $client->getEventDispatcher()->addListener('request.dequeued', function ($event) use(&$dequeueings) {
         $dequeueings++;
     });
     $requests = array($client->get()->setResponse(new Response(200), true), $client->get()->setResponse(new Response(200), true), $client->get()->setResponse(new Response(200), true), $client->get()->setResponse(new Response(200), true));
     foreach ($client->send($requests) as $response) {
         $this->assertEquals(200, $response->getStatusCode(), "Status code");
     }
     $this->assertEquals(2, $queueings, "Queueings");
     $this->assertEquals(2, $dequeueings, "Dequeueings");
 }
예제 #2
0
 /**
  * @param string $appKey
  * @param string $secretKey
  * @param string $apiBaseUrl
  * @param int $connectTimeout
  * @param int $requestTimeout
  * @param Service\CryptService $cryptService
  * @param Cache\Cache $cache
  * @param int $publicKeyTTL
  * @param \Psr\Log\LoggerInterface $logger
  * @return Service\GuzzleApiService
  */
 private static function getGuzzleApiService($appKey, $secretKey, $apiBaseUrl, $connectTimeout, $requestTimeout, Service\CryptService $cryptService, Cache\Cache $cache, $publicKeyTTL, \Psr\Log\LoggerInterface $logger = null)
 {
     $guzzle = new \Guzzle\Http\Client($apiBaseUrl, array("redirect.disable" => true, 'request.options' => array("timeout" => $requestTimeout, "connect_timeout" => $connectTimeout)));
     if ($logger) {
         $guzzle->getEventDispatcher()->addListener(\Guzzle\Http\Client::CREATE_REQUEST, function (\Guzzle\Common\Event $event) use($logger) {
             $logger->debug("Guzzle preparing to send request", $event->toArray());
         });
     }
     $apiService = new Service\GuzzleApiService($appKey, $secretKey, $guzzle, $cryptService, $cache, $publicKeyTTL, $logger);
     return $apiService;
 }