Guzzle’s POST request timing out from server (locally works)

  apache, guzzle, php, post, request

I’m trying to POST request my API, which is in a nginx server, from an apache server, but no response is obtained.
Requests from localhost to the same nginx server work fine. But, when the same snippet is executed in the production server, we get a time out, and Guzzle throws an exception after few seconds.

Exception threw:

<br />
<b>Fatal error</b>:  Uncaught GuzzleHttpExceptionConnectException: cURL error 7: Failed connect to 192.140.88.50:80; Connection timed out (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for 192.140.88.50/infotech/selecionar_cidades in /var/www/html/abmcash.com.br/web/abmNew2/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:210
Stack trace:
#0 /var/www/html/abmcash.com.br/web/abmNew2/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(158): GuzzleHttpHandlerCurlFactory::createRejection(Object(GuzzleHttpHandlerEasyHandle), Array)
#1 /var/www/html/abmcash.com.br/web/abmNew2/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(110): GuzzleHttpHandlerCurlFactory::finishError(Object(GuzzleHttpHandlerCurlHandler), Object(GuzzleHttpHandlerEasyHandle), Object(GuzzleHttpHandlerCurlFactory))
#2 /var/www/html/abmcash.com.br/web/abmNew2/vendor/guzzlehttp/guzzle/src/Handler/CurlHandler.php(47): GuzzleHttpHandlerCurlFactory::finish(Object(GuzzleHttpHandlerCurlHandler), Object(GuzzleHttpHandlerEasyHandle), Objec in <b>/var/www/html/abmcash.com.br/web/abmNew2/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php</b> on line <b>210</b><br />

Ping and Traceroute commands were executed and both of them succeded.

None of the machines have any firewall rule preventing any kind of communication between them.

This is the snippet that sends the request:

$base_url = "127.0.0.1:8000";
$url = $base_url . $rota;
$client = new Client([
    'headers' => ['Content-Type' => 'application/json;charset=utf-8']
]);

$payload =  json_encode($data);

$response = $client->post($url, ['body' => $payload]);

PHP version: 7.4.20

Edit: Apache is listening the port 80 and Nginx is listening the port 8000, and both of them are up and running

Source: Ask PHP

LEAVE A COMMENT