1

My code:

$iterator = [$object1, $object2, $object3, .....];

$client = new Client();

$requests = function() use ($iterator) {
    foreach ($iterator as $key => $object) {
        yield $key => new Request('GET', $object->url);
    }
};

$pool = new Pool($client, $requests(), [
    'fulfilled' => function($response, $index) use ($iterator) {
        $iterator[$index]->success($response);
    },
    'rejected' => function($reason, $index) use ($iterator) {
        $iterator[$index]->error($reason);
    },
]);

Now i need to set different options (body, timeouts, etc.) for each request in pool, not for all pool.
I can set different headers for each request new Request('GET', $object['url'], $headers), but I don't understand how to set different options for each request.
Is it possible?

Max P.
  • 5,579
  • 2
  • 13
  • 32
  • Modify the objects in your $iterator array to include those details where they differ from the default values – Mark Baker Apr 21 '16 at 11:11
  • Objects in iterator contain all necessary options, but I don't understand how to pass them to pool. – Max P. Apr 21 '16 at 11:15
  • Instantiate your Request in the iterator; apply the settings; then yield the Request back – Mark Baker Apr 21 '16 at 11:18
  • I instantiate Request in the iterator `yield $key => new Request('GET', $object->url)`, but I can pass to it only headers as 3-rd parameter, not options (timeouts, body, ..). – Max P. Apr 21 '16 at 11:24
  • Surely options can be passed as a associative array as a third argument when instantiating the request? `new Request('GET', $object->url, ['timeout' => 20, 'connect_timeout' => 1.5]);` – Mark Baker Apr 21 '16 at 11:37
  • Not all options, only http headers – Max P. Apr 21 '16 at 11:39
  • Please refer to http://stackoverflow.com/questions/36486069/whats-the-correct-way-to-use-guzzle-6-to-create-pool-of-asynchronous-json-reque . – Yanhui Xie May 24 '16 at 15:08

0 Answers0