What's the correct way to use Guzzle 6 to create pool of asynchronous json requests to send to API endpoints?

后端 未结 2 755
慢半拍i
慢半拍i 2021-01-18 07:07

My objective is to use Guzzle 6 to create a pool of asynchronous requests that PUT json data. Then monitor each $promise success/failure.

For comparison to my POOL c

2条回答
  •  清酒与你
    2021-01-18 07:43

    Hopefully, someone else will jump in and let me know if there is a more correct way to accomplish my objective, but after looking under the hood in Guzzle I realized new Request()'s 3rd parameter was looking for header information, and the 4th parameter was looking for a body. So the following code works using the Pool.:

    foreach ($syncRequests as $key => $headers) {
        yield new Request('PUT', "{$uri}{$headers['endpoint']}", ['Content-type' => 'application/json'], json_encode(['json' => ['nonce' => $headers['json']]]));
    }
    

    Also in docs for Psr7\Request

提交回复
热议问题