This was orginally an answer I wrote for Laracasts.
$urls = collect([
'http://google.com',
'http://googsdfsdle.com',
'http://yelp.com',
'http://testwwerer.com',
]);
// make requests
$responses = Http::pool( fn(Pool $pool) =>
$urls->each( fn($url) => $pool->head($url))
);
// check responses
$keyedResponses = collect($responses)->map( fn($response) => match (true) {
$response instanceof \Illuminate\Http\Client\Response
&& $response->ok()
=> 'good url',
$response instanceof \GuzzleHttp\Exception\ConnectException
&& Str::contains($response->getMessage(), 'cURL error 6: Could not resolve host:')
=> 'Could not resolve',
default
// maybe double check this url. There could have been some other network issue, etc...
=> 'something else happened'
});
// process results
$urls->each(fn ($item, $key) => match($keyedResponses[$key]) {
'good url' => dump("save $item its good"), // InternalUrls::update([ ... ]),
'Could not resolve' => dump("kill $item its bad"), // mark as bad
'something else happened' => dump("something else happened with $item") // mark for recheck
});