I'm running a PHP Wordpress site that's part of an ecosystem of sites.
The Wordpress site relies on another service to provide the site's navigation menu. I'm trying to make the Wordpress site more resilient whenever the other service goes down or is not available. Wordpress is using Guzzle to make a network request from the other service, but I cannot seem to configure it to not throw an exception whenever it cannot reach the other service.
I've tried setting the http_errors
, timeout
, and connect_timeout
on Guzzle, but I still get an exception whenever the other service is down.
Here's an example of the request that I'm making:
$client = new GuzzleHttp\Client(['base_uri' => 'http://localhost']);
$response = $client->get('/menu', [
'http_errors' => false,
'connect_timeout' => 5,
'timeout' => 5,
]);
Which raises a Fatal Error:
Fatal error: Uncaught Exception: cURL error 7: Failed to connect to localhost port 80 after 0 ms: Connection refused (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)
I have also tried:
$client = new GuzzleHttp\Client([
'base_uri' => 'http://localhost',
'http_errors' => false,
'connect_timeout' => 5,
'timeout' => 5,
]);
$response = $client->get('/menu');
Can I suppress the connection refused error?