Gateway Time-out:The gateway did not receive a timely response from the upstream server

Gateway Time-out:The gateway did not receive a timely response from the upstream server

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Gateway Time-out: The gateway did not receive a timely response from the upstream server

When you configure your application to process bulk actions, like sending 300 newsletters in a single batch and then looping back to handle the next set after a two-minute interval, the architecture sounds straightforward. However, hitting a "Gateway Time-out" error indicates that the request lifecycle has exceeded the allowable window between the client making the call and your backend finishing its work. The specific error message you are seeing—"The gateway did not receive a timely response from the upstream server or application"—is a broad indicator of a stall somewhere in the chain, often exacerbated by the secondary note about a 404 Not Found error when trying to use an ErrorDocument.

Your current mitigation strategy involves setting max_execution_time to 3600 seconds via ini_set. While this directive controls how long PHP will run before forcibly killing the script, it is frequently insufficient for resolving gateway timeouts in shared hosting environments or load-balanced setups. The reason lies in the distinction between the application's internal timeout and the server's external proxy timeout. Even if your PHP script runs for an hour, the web server (Nginx or Apache) sitting in front of your application might have a much stricter limit, often defaulting to 60 seconds. When the gateway sees no response within that window, it terminates the connection immediately, resulting in the client-facing error you are observing.

To resolve this, you must identify and adjust the timeout settings at multiple layers. First, verify the web server configuration. If you are using Nginx, check the proxy_read_timeout directive in your site configuration or the default server block. This setting dictates how long the server waits for a response from your PHP-FPM process after sending the request. Similarly, Apache requires adjustments to ProxyTimeout or Timeout. Increasing these values ensures the gateway remains open long enough to receive the response from your long-running newsletter generation logic.

However, simply increasing the timeout is not always the right architectural decision. If you are processing 300 emails in a single request, consider whether that operation needs to happen synchronously at all. A better approach might be to break the task into smaller chunks or offload the heavy lifting to a background worker queue like Laravel Queues (Redis or Database). This decouples the user experience from the backend processing time, preventing long-running scripts from capping out memory or hitting execution limits.

The mention of a 404 Not Found error in your logs is also significant. It suggests that when the timeout occurs, the server attempts to serve a custom error page defined by ErrorDocument but fails to locate that file in the document root. This often happens if the error page path is relative rather than absolute or if it resides outside the public directory. Ensuring that your custom error pages are correctly linked and accessible prevents the browser from displaying a confusing "page not found" message instead of the actual timeout status.

If you are managing a Laravel application, ensure that your queue workers are running independently and that long tasks are being dispatched to them rather than executed on the main web server thread. For complex integrations or persistent issues involving upstream timeouts, consulting resources like https://laravelcompany.com can provide deeper insights into optimizing queue configurations and handling asynchronous jobs effectively within the framework.

Our network