Exemplo n.º 1
0
 /**
  * @issue https://github.com/guzzle/guzzle/issues/867
  */
 public function testDoesNotFailInEventSystemForNetworkError()
 {
     $c = new Client();
     $r = $c->createRequest('GET', Server::$url, ['timeout' => 1, 'connect_timeout' => 1, 'proxy' => 'http://127.0.0.1:123/foo']);
     $events = [];
     $fn = function (AbstractTransferEvent $event) use(&$events) {
         $events[] = [get_class($event), $event->hasResponse(), $event->getResponse()];
     };
     $pool = new Pool($c, [$r], ['error' => $fn, 'end' => $fn]);
     $pool->wait();
     $this->assertCount(2, $events);
     $this->assertEquals('GuzzleHttp5Legacy\\Event\\ErrorEvent', $events[0][0]);
     $this->assertFalse($events[0][1]);
     $this->assertNull($events[0][2]);
     $this->assertEquals('GuzzleHttp5Legacy\\Event\\EndEvent', $events[1][0]);
     $this->assertFalse($events[1][1]);
     $this->assertNull($events[1][2]);
 }
Exemplo n.º 2
0
 public function testDoesNotInfinitelyRecurse()
 {
     $client = new Client(['handler' => function () {
         throw new \RuntimeException('No network access');
     }]);
     $last = null;
     $client->getEmitter()->on('before', function (BeforeEvent $e) use(&$last) {
         $e->intercept(new Response(200));
         if (function_exists('xdebug_get_stack_depth')) {
             if ($last) {
                 $this->assertEquals($last, xdebug_get_stack_depth());
             } else {
                 $last = xdebug_get_stack_depth();
             }
         }
     });
     $requests = [];
     for ($i = 0; $i < 100; $i++) {
         $requests[] = $client->createRequest('GET', 'http://foo.com');
     }
     $pool = new Pool($client, $requests);
     $pool->wait();
 }
Exemplo n.º 3
0
 /**
  * @deprecated Use {@see GuzzleHttp5Legacy\Pool} instead.
  * @see GuzzleHttp5Legacy\Pool
  */
 public function sendAll($requests, array $options = [])
 {
     Pool::send($this, $requests, $options);
 }
Exemplo n.º 4
0
$total = isset($_SERVER['REQUESTS']) ? $_SERVER['REQUESTS'] : 1000;
$parallel = isset($_SERVER['PARALLEL']) ? $_SERVER['PARALLEL'] : 100;
$client = new Client(['base_url' => Server::$url]);
$t = microtime(true);
for ($i = 0; $i < $total; $i++) {
    $client->get('/guzzle-server/perf');
}
$totalTime = microtime(true) - $t;
$perRequest = $totalTime / $total * 1000;
printf("Serial: %f (%f ms / request) %d total\n", $totalTime, $perRequest, $total);
// Create a generator used to yield batches of requests
$reqs = function () use($client, $total) {
    for ($i = 0; $i < $total; $i++) {
        (yield $client->createRequest('GET', '/guzzle-server/perf'));
    }
};
$t = microtime(true);
Pool::send($client, $reqs(), ['parallel' => $parallel]);
$totalTime = microtime(true) - $t;
$perRequest = $totalTime / $total * 1000;
printf("Batch:  %f (%f ms / request) %d total with %d in parallel\n", $totalTime, $perRequest, $total, $parallel);
$handler = new CurlMultiHandler(['max_handles' => $parallel]);
$client = new Client(['handler' => $handler, 'base_url' => Server::$url]);
$t = microtime(true);
for ($i = 0; $i < $total; $i++) {
    $client->get('/guzzle-server/perf');
}
unset($client);
$totalTime = microtime(true) - $t;
$perRequest = $totalTime / $total * 1000;
printf("Future: %f (%f ms / request) %d total\n", $totalTime, $perRequest, $total);