小编Jon*_*n H的帖子

狂饮池异步请求范围

我正在使用以下代码通过Guzzle for PHP发出并发请求:

use GuzzleHttp\Pool;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;

$client = new Client();

$myvar = 12345;

$requests = function ($total) {
    $uri = 'http://127.0.0.1:8126/guzzle-server/perf';
    for ($i = 0; $i < $total; $i++) {
        yield new Request('GET', $uri);
    }
};

$pool = new Pool($client, $requests(100), [
    'concurrency' => 5,
    'fulfilled' => function ($response, $index) {
        // this is delivered each successful response
        var_dump($myvar);
    },
    'rejected' => function ($reason, $index) {
        // this is delivered each failed request
    },
]);

// Initiate …
Run Code Online (Sandbox Code Playgroud)

php guzzle

2
推荐指数
1
解决办法
739
查看次数

标签 统计

guzzle ×1

php ×1