What's the correct way to use Guzzle 6 to create pool of asynchronous json requests to send to API endpoints?
<p>My objective is to use <a href="http://docs.guzzlephp.org/en/latest/quickstart.html#concurrent-requests" rel="noreferrer">Guzzle 6</a> to create a pool of asynchronous requests that PUT json data. Then monitor each $promise success/failure.</p>

<p>For comparison to my POOL code example, the following single request to $client->request() converts the 3rd parameter to encoded json and then adds the Content-type:application/json.**</p>

<pre><code>$client = new Client([
    'base_uri' =&gt; BASE_URL . 'test/async/', // Base URI is used with relative requests
    'timeout'  =&gt; 0, // 0 no timeout for operations and watching Promises
]);

$response = $client-&gt;request('PUT', 'cool', ['json' =&gt; ['foo' =&gt; 'bar']]);
</code></pre>

<p><strong>On the receiving API endpoint, I can read the json from the single request above by doing the following:</strong>
</p>

<pre><code>$json = file_get_contents('php://input');
$json = json_decode($json, true);
</code></pre>

<p>Using the <a href="http://docs.guzzlephp.org/en/latest/quickstart.html#concurrent-requests" rel="noreferrer">concurrent requests example in the docs, for creating a Pool of asynchronous requests</a> using new Request(), I hoped the same parameters (method, url endpoint, json flag) could be used, as in the single $client->request() example above. However, <code>yield new Request()</code> does not handle the 3rd json parameter like <code>$client-&gt;request()</code>. <strong>What is the correct Guzzle function to call from my Pool code to set json and content-type correctly? Or is there a better way to create a large pool of asynchronous requests and monitor their outcome?</strong></p>

<p><strong>POOL code example:</strong></p>

<pre class="lang-php prettyprint-override"><code>$this-&gt;asyncRequests = [
    [
        'endpoint' =&gt; 'cool'
    ],
    [
        'endpoint' =&gt; 'awesome'
    ],
    [
        'endpoint' =&gt; 'crazy'
    ],
    [
        'endpoint' =&gt; 'weird'
    ]
];

$client = new Client([
    'base_uri' =&gt; BASE_URL, // Base URI is used with relative requests
    'timeout'  =&gt; 0 // 0 no timeout for operations and watching Promises
]);

$requests = function ($asyncRequests) {
    $uri = BASE_URL . 'test/async/';

    foreach ($asyncRequests as $key =&gt; $data) {
        yield new Request('PUT', "{$uri}{$data['endpoint']}", ['json' =&gt; ['foo' =&gt; 'bar']]);
    }
};

$pool = new Pool($client, $requests($this-&gt;asyncRequests), [
    'concurrency' =&gt; 10,
    'fulfilled' =&gt; function ($response, $index) {
        $this-&gt;handleSuccessPromises($response, $index);
    },
    'rejected' =&gt; function ($reason, $index) {
        $this-&gt;handleFailurePromises($reason, $index);
    },
]);

$promise = $pool-&gt;promise(); // Initiate the transfers and create a promise

$promise-&gt;wait(); // Force the pool of requests to complete.
</code></pre>