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

abkrim's avatar
Level 13

Strange behavior with HTTP client and timeout

After a series of tests, because I couldn't understand what was happening to me in the end, I chose to gradually increase the timeout, until I reached the point where I suspected there was a problem.

## 60 seconds of timeout not work

Yes, if I use a timeout equal to or greater than 60 seconds. the HTTP client no longer returns anything, even if the server returns data to it.

For the tests, use a fake endpoint that does not offer a timeout with error 500 until after 3 minutes.

I started with a 20-second timeout, went up to 30, 40, 50, and wham. At 60 it stopped working. Of course 59 works fine.

The client never died and the code set for the debug was never reached.

I have checked the configuration of my PHP instance in Sail, and there is no limit to 60 seconds

So with these data I don't know where the error is that I can correct so that the HTTP client obtains a timeout error when it is equal to or greater than 60.

The code is in a job that works in queues with redis (horizon as supervisor)

I needed a lot of calls to ray because I didn't understand what was going on. That was what it showed me, that the call after 60 seconds remains without getting an answer or timeout. It doesn't even respond even though it reaches 180 from the server, which returns a 500 error.

code

try {
// I use the code below to continue working with the app, but I need a timeout of 160 seconds.  
//            $timeout = (config('sitelight.queues.modem.api.timeout') >= 60)
//                ? 59
//                : (config('sitelight.queues.modem.api.timeout'));
    $timeout = 60;
    ray('Check code enter '); \ If $timeout >= 60 Only one time read this message and NEVER get Exception or $reponse
    $response = Http::timeout($timeout)
        ->withHeaders([
            'Accept' => 'application/json',
        ])
        ->withOptions([
            'verify' => app()->environment('production'),
        ])
        ->get($this->endpoint);
} catch (ConnectionException $e) {
\ If $timeout >= 60 Only one time read this message and NEVER get Exception or 
    ray($e->getMessage());
    ray($this->tries);
    ray($this->attempts());

    if ($this->attempts() < $this->tries) {
        ray("Attempts ".$this->attempts());
        //$this->fail();
        throw new Exception("$modem error timeout server with response code}");
    } else {
        ray("Attempts ".$this->attempts(). " We need save data");
        $this->saveErrorInDatabase($e->getMessage(),408);
        //$this->fail();
        return;
    }
} catch (Exception $e) {
\ If $timeout >= 60 Only one time read this message and NEVER get Exception or 
    ray($e->getMessage())->die();
}

0 likes
3 replies
fideloper's avatar

60 seconds is probably the max execution time set in php.ini

Perhaps try calling that code from a console command, which often has no max execution time (while an http request might). It’s possible theres a limit set for cli-called php as well tho.

abkrim's avatar
Level 13

I just thought of that, but check the configuration and even modify it. max_execution_time 180 (in master and 180 in local) (get from php.ini) Also check max_input_time 120, 120

Even so, I think that the HTTP client should end with an error, the execution, and not be left without sending any type of response after the possible timeout error returned by php.

Reviewing how Laravel Sail works, I see that the http service is Laravel Serve, and I think that is where the crash occurs

StanleyPeters's avatar

We were getting ERROR: cURL error 28: Operation timed out after 30001 milliseconds with 0 bytes received. Our production max_execution_time was already 60s and the server I was calling was successfully processing just not quick enough. Adding timeout(90) to Http is working in prod env. I think this timeout is for cURL.

Please or to participate in this conversation.