Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Guzzle6中创建批处理请求?_Php_Guzzle_Guzzle6 - Fatal编程技术网

Php 如何在Guzzle6中创建批处理请求?

Php 如何在Guzzle6中创建批处理请求?,php,guzzle,guzzle6,Php,Guzzle,Guzzle6,我需要发送多个请求,所以我想实现一个批处理请求 我们怎样才能在狂饮中做到这一点 使用旧方法: $client->send(array( $client->get($courses), //api url $client->get($job_categories), //api url )); 给了我一个错误: GuzzleHttp\Client::send() must implement interface Psr\Http\Message\Reques

我需要发送多个请求,所以我想实现一个批处理请求

我们怎样才能在狂饮中做到这一点

使用旧方法:

$client->send(array(
    $client->get($courses),  //api url
    $client->get($job_categories), //api url
)); 
给了我一个错误:

GuzzleHttp\Client::send() must implement interface Psr\Http\Message\RequestInterface, array given

试试这样的

    $client = new Client();
    foreach ($links as $link) {
        $requests[] = new Request('GET', $link);
    }

    $responses = Pool::batch($client, $requests, array(
        'concurrency' => 15,
    ));

    foreach ($responses as $response) {
         //do something
    }
别忘了

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