本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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);
示例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));