Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ace's avatar
Level 7

HTTP Connection Failure

I got a HTTP Connection Failure and 502 error for requests between a Service API I use that POST's to my API on laravel forge. Everything was working fine. then I got a bunch of connection fails. I am on digital ocean.

Where do I check the connection logs, nginx?

I see no error in the laravel logs itself

0 likes
5 replies
Ace's avatar
Level 7

I found this error: 2018/03/20 11:01:04 [error] 4685#4685: *16223 connect() to unix:/var/run/php/php7.1-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client:

this came out of the blue. same amount of traffic and requests as before

ejdelmonico's avatar

Did you notice if you had a bunch file probing in the logs? Max connections were probably exceeded if so. You definitely need to impose strict limits for an API. Middleware can be used effectively for that.

Ace's avatar
Level 7

@ejdelmonico thanks for the reply,

where can I set/check max connections and how can Middleware be used?

in file bunch file probing in the logs do you mean bots in the access log?

ejdelmonico's avatar

I would try middleware first because it will limit the number of attempts which is probably the issue. Here is a simple middleware for limiting attempts:

namespace App\Http\Middleware;

use App\Traits\ApiResponser;
use Illuminate\Routing\Middleware\ThrottleRequests;

class CustomThrottleRequests extends ThrottleRequests
{
    use ApiResponser;

    /**
     * Create a 'too many attempts' response.
     *
     * @param  string $key
     * @param  int $maxAttempts
     * @return \Symfony\Component\HttpFoundation\Response
     */
    protected function buildResponse($key, $maxAttempts)
    {
        $response = $this->errorResponse('Too Many Attempts.', 429);
        $retryAfter = $this->limiter->availableIn($key);

        return $this->addHeaders(
            $response,
            $maxAttempts,
            $this->calculateRemainingAttempts($key, $maxAttempts, $retryAfter),
            $retryAfter
        );
    }
}

Then, in App\Http\Kernel.php and in the api array set something like throttle:10,1. In the same file and inside the $routeMiddleware you should add the class with something like throttle => \App\Http\Middleware\CustomZThrottleRequests. That should do it if I didn't forget anything.

Ace's avatar
Level 7

Hi thanks I will try and implement it,

I upgraded to php 7.2 on forge and

I still get these errors for incoming API requests even on individual requests., so it is not matter of multiple connections.

very strange?!?

the forge support said my server configuration is OK.

Please or to participate in this conversation.