當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Client::sendAll方法代碼示例

本文整理匯總了PHP中GuzzleHttp\Client::sendAll方法的典型用法代碼示例。如果您正苦於以下問題:PHP Client::sendAll方法的具體用法?PHP Client::sendAll怎麽用?PHP Client::sendAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在GuzzleHttp\Client的用法示例。


在下文中一共展示了Client::sendAll方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: forwardIpn

 /**
  * @param IpnEntity $ipn
  * @return bool
  */
 public function forwardIpn(IpnEntity $ipn)
 {
     $urls = $ipn->getForwardUrls();
     if (!empty($urls)) {
         $requests = [];
         foreach ($urls as $url) {
             $request = $this->guzzle->createRequest('post', $url);
             $request->setHeader($this->customHeader, $this->getKey());
             if (in_array($url, $this->disabledJsonFormatting)) {
                 $request->getQuery()->merge($ipn->toArray());
             } else {
                 $request->setHeader('content-type', 'application/json');
                 if ($this->formatter) {
                     $response = $this->formatter->formatJsonResponse($ipn);
                 } else {
                     $response = ['ipn' => $ipn->toArray()];
                 }
                 $request->setBody(Stream::factory(json_encode($response)));
             }
             $requests[] = $request;
         }
         $this->guzzle->sendAll($requests, ['parallel' => $this->maxRequests]);
         return true;
     }
     return false;
 }
開發者ID:iyoworks,項目名稱:ipn-forwarder,代碼行數:30,代碼來源:Forwarder.php

示例2: testCanSetCustomParallelAdapter

 public function testCanSetCustomParallelAdapter()
 {
     $called = false;
     $pa = new FakeParallelAdapter(new MockAdapter(function () use(&$called) {
         $called = true;
         return new Response(203);
     }));
     $client = new Client(['parallel_adapter' => $pa]);
     $client->sendAll([$client->createRequest('GET', 'http://www.foo.com')]);
     $this->assertTrue($called);
 }
開發者ID:mahersafadi,項目名稱:joindin-api,代碼行數:11,代碼來源:ClientTest.php

示例3: testSendsAllInParallel

 public function testSendsAllInParallel()
 {
     $client = new Client();
     $client->getEmitter()->attach(new Mock([new Response(200), new Response(201), new Response(202)]));
     $history = new History();
     $client->getEmitter()->attach($history);
     $requests = [$client->createRequest('GET', 'http://test.com'), $client->createRequest('POST', 'http://test.com'), $client->createRequest('PUT', 'http://test.com')];
     $client->sendAll($requests);
     $requests = array_map(function ($r) {
         return $r->getMethod();
     }, $history->getRequests());
     $this->assertContains('GET', $requests);
     $this->assertContains('POST', $requests);
     $this->assertContains('PUT', $requests);
 }
開發者ID:EarthTeam,項目名稱:earthteam.net,代碼行數:15,代碼來源:ClientTest.php

示例4: isset

 *     make perf
 *     # With custom options
 *     REQUESTS=100 PARALLEL=5000 make perf
 */
require __DIR__ . '/bootstrap.php';
use GuzzleHttp\Client;
use GuzzleHttp\Tests\Server;
// Wait until the server is responding
Server::wait();
// Get custom make variables
$total = isset($_SERVER['REQUESTS']) ? $_SERVER['REQUESTS'] : 1000;
$parallel = isset($_SERVER['PARALLEL']) ? $_SERVER['PARALLEL'] : 25;
$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 to sendAll
$reqs = function () use($client, $total) {
    for ($i = 0; $i < $total; $i++) {
        (yield $client->createRequest('GET', '/guzzle-server/perf'));
    }
};
$t = microtime(true);
$client->sendAll($reqs(), ['parallel' => $parallel]);
$totalTime = microtime(true) - $t;
$perRequest = $totalTime / $total * 1000;
printf("Parallel: %f (%f ms / request) %d total with %d in parallel\n", $totalTime, $perRequest, $total, $parallel);
開發者ID:mahersafadi,項目名稱:joindin-api,代碼行數:31,代碼來源:perf.php

示例5: Client

<?php

require __DIR__ . '/../vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Subscriber\Log\LogSubscriber;
use GuzzleHttp\Subscriber\Log\Formatter;
$httpClient = new Client(['base_url' => 'https://httpbin.org']);
// Attach a subscriber for logging the request and response.
$logger = new LogSubscriber(STDOUT, new Formatter(Formatter::DEBUG));
$httpClient->getEmitter()->attach($logger);
// Create a generator that emits PUT requests.
$createPutRequests = function ($limit, $start = 1) use($httpClient) {
    for ($i = $start; $i <= $limit; $i++) {
        (yield $httpClient->createRequest('PUT', 'put', ['json' => ['first_name' => 'John' . str_pad($i, 4, '0', STR_PAD_LEFT), 'last_name' => 'Doe', 'age' => rand(18, 60)]]));
    }
};
// Execute a batch of requests.
$httpClient->sendAll($createPutRequests(5));
開發者ID:josefabian2588,項目名稱:sunshinephp-guzzle-examples,代碼行數:18,代碼來源:guzzle-4.php


注:本文中的GuzzleHttp\Client::sendAll方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。