Home » Php » php – How to know the requested url in guzzle?

php – How to know the requested url in guzzle?

Posted by: admin February 25, 2020 Leave a comment

Questions:

I try load many urls async but can’t think of anything how can I know proccess url..Code below:

$requests = function ($total, $urls) {
    for ($i = 0; $i < $total; $i++) {
        yield new Request('GET', $urls[$i]);
    }
};

$pool = new Pool($client, $requests(50, $urls), [
    'concurrency' => 5,
    'fulfilled' => function (Response $response, $index) {
          // How i can this know what url was proccessed? 

    },
    'rejected' => function (RequestException $reason, $index) {
         // And here too..
    },
]);


$promise = $pool->promise();

$promise->wait();

Please help, any ideas..

How to&Answers: