Why am I getting this error: Apache “proxy_fcgi” - The timeout specified has expired - Error dispatching request

Why am I getting this error: Apache “proxy_fcgi” - The timeout specified has expired - Error dispatching request

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

Stefan Bogdanescu

Founder & Senior Architect

Why am I getting this error: Apache "proxy_fcgi" - The timeout specified has expired

When you see the proxy_fcgi:error stating that a specific timeout has expired, it usually means Apache stopped waiting for your PHP process to respond because it exceeded the maximum time allowed for a single request. In your logs, the message explicitly mentions AH01075: Error dispatching request, which tells us that Apache initiated the connection to your FastCGI wrapper (likely fcgid or php-fpm) but never received the final response body in time.

The specific error code (70007) often appears when a worker thread is forced to terminate before it can send the HTTP response headers back to the client. While you might suspect that a single long-running script is the culprit, simply increasing max_execution_time inside your PHP script using ini_set() does not always solve the problem if the underlying Apache or PHP-FPM configuration has stricter limits.

Understanding the Timeout Hierarchy

To fix this, you need to understand where the timeout actually lives in the request lifecycle. There are three primary layers that can enforce a time limit:

  1. Apache (proxy_fcgi): This is the most restrictive layer. In your error log, it says The timeout specified has expired. By default, Apache's ProxyTimeout or Timeout directive might be set to 30 or 60 seconds. If the PHP script takes longer than this, Apache kills the connection immediately, regardless of what PHP thinks.
  2. PHP-FPM / fcgiwrap: The FastCGI process managing your PHP scripts has its own limits. You need to check pm.max_requests, request_terminate_timeout, or similar directives depending on whether you are using php-fpm pool configuration or the standalone fcgid wrapper.
  3. PHP Internal Limits: Directives like max_execution_time and memory_limit inside php.ini.

The critical mistake developers make is assuming that setting ini_set('max_execution_time', 0); at the top of a file overrides Apache's timeout. It does not. If Apache kills the connection after 30 seconds, PHP will never even get the chance to execute your ini_set() logic effectively because the socket is already closed.

Diagnosing the Root Cause

Looking at your logs, the timestamps show requests failing roughly every 5 minutes (e.g., 22:10:59, then 22:16:27, then 22:21:52). This pattern suggests a consistent threshold being hit. If your default Apache timeout is set to 30 seconds and your script logic involves external API calls or heavy database queries, it might be taking longer than expected under load.

You should start by inspecting your Apache configuration file (often httpd.conf, apache2.conf, or a specific VirtualHost config). Look for directives like:
Timeout 30
or
ProxyTimeout 60

If these values are lower than your actual script duration, you must increase them. For example:

Timeout 300
ProxyTimeout 300

Be cautious when increasing these values; if the application hangs indefinitely due to a deadlock or infinite loop, raising the timeout simply prolongs the unresponsiveness of your server for all users.

Checking PHP-FPM Configuration

If you are using php-fpm as the FastCGI backend (which is common in modern stacks), the error might originate from there instead of Apache's proxy module. You need to check your pool configuration file, typically located at /etc/php/7.x/fpm/pool.d/www.conf.

Look for a directive named request_terminate_timeout. If it is set to 30s, you will get this exact error once that duration passes. Update it accordingly:

request_terminate_timeout = 60s

Also, ensure that php_admin_value[open_basedir] or other security restrictions aren't causing the script to hang waiting for file access that never happens.

The Role of AJAX and Client-Side Timeouts

You mentioned that your XMLHttpRequests sometimes work and sometimes fail. This is a classic symptom of inconsistent backend performance. If your PHP script occasionally takes 35 seconds but usually takes 20, Apache will kill the request when it hits the limit on those slower runs.

On the client side (JavaScript), you should also consider implementing a sensible timeout for your AJAX calls to prevent users from waiting indefinitely if the server is indeed slow. You can add a timeout property to your XMLHttpRequest:

var xhr = new XMLHttpRequest();
xhr.timeout = 10000; // Timeout after 10 seconds

xhr.addEventListener('timeout', function() {
    xhr.abort();
    console.log('Request timed out');
});

This ensures that even if the server doesn't respond, your UI can handle the failure gracefully rather than showing a frozen loading spinner.

Summary of Fixes

To resolve the proxy_fcgi timeout error:

  1. Increase Timeout and ProxyTimeout in your Apache configuration to match your application's needs.
  2. Adjust request_terminate_timeout in your PHP-FPM pool configuration if applicable.
  3. Investigate why your scripts are taking so long; external API calls or complex queries are frequent suspects.
  4. Remember that ini_set('max_execution_time') is secondary and won't override Apache-level timeouts.

By aligning these timeout values, you ensure that Apache waits long enough for your PHP logic to complete before forcibly terminating the connection.

Our network