A
A
Andy Developer2017-04-20 23:51:46
PHP
Andy Developer, 2017-04-20 23:51:46

Guzzle 6 Pool: sink and filename in fulfilled, how to get?

Please help with guzzle.
There is the following code

$requests = function ($total) use ($client) {
            foreach($this->downloadLinks as $key => $link) {

                preg_match('/([0-9]*)\.mp4/', $link, $matches);
                $resource = getcwd().'/videos/'.$this->downloadPath.'/'.$matches[0];

                yield function () use ($client, $link, $resource) {
                    return $client->getAsync($link, [
                        'sink' => $resource,
                        'proxy' => 'tcp://'.$this->proxies[ mt_rand(0, count($this->proxies)-1)]
                    ]);
                };
            }
        };





        $pool = new Pool($this->browser, $requests(count($requests)), [
            'concurrency' => $concurrency,
            'fulfilled' => function ($response, $index) {
               
               как тут получить имя скачанного фала?

            },
            'rejected' => function ($reason, $index) {
              echo 'rejcted';
            },
        ]);

        $promise = $pool->promise();
        $promise->wait();

Files are downloaded as expected, but how to get the name of the downloaded file in fulfilled?
I can't figure it out.
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andy Developer, 2017-04-21
@UmbrellaCoders

I did it via middlewears docs.guzzlephp.org/en/latest/handlers-and-middlewa... I
added the necessary data to the Response and already in fulfilled I got them $request->getHeader('custom_header');

A
Alexander Aksentiev, 2017-04-21
@Sanasol

Or add an identifier to yield if you need to get something of your own.
Or look repsonse, there should be all the headers and etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question