A PHP timeout occurs when a Drupal or PHP request takes longer than five minutes to produce output, terminates, and produces an HTTP 500 error. Most web browsers, depending on the client, don't wait longer than two minutes before discontinuing a request and displaying an error.
Long-running processes consume server resources. If there are too many processes running, it impairs the performance of your application. The Acquia Cloud web stack accommodates requests that require extra time to complete, but does not to allow a process to run indefinitely.
The following are potential causes of PHP timeouts:
cron.phprequest that runs too long
- Complex database queries on large quantities of data; for example, multiple JOINs on large database tables
- Extended database table locks; for example, explicit table locks or structural changes on large tables
- Drupal Views that produce complex database queries on large databases
- Calls to slow or unresponsive external service providers using RPC calls, the cURL library,
file_get_contents($url), or similar methods
- Processing very large database result sets in PHP code
- File operations that involve very large files or directories
- PHP bugs; for example, infinite loops or infinite recursions
- Calls to the
sleep()function for extended lengths of time; for example, as an exponential back-off throttle
Some potential solutions for PHP timeout issues include:
- Use Drush cron instead of
cron.php. See Using scheduled jobs to maintain your application.
- Enable Drupal's block cache and views cache. All standard caching techniques are also recommended.
- Set the call timeout to external services to less than 30 seconds, in case the call becomes unresponsive.
- Optimize your database queries to examine as few rows and tables as possible to produce the same result.
- Profile your PHP code to find the functions that take extended amounts of time to complete.
- Use cron jobs for long-running tasks. Consider moving long-running tasks into cron and caching the results.
Finding problematic pages
To find problematic pages, do the following:
- Use an application performance monitor tool (such as New Relic) to monitor applications in production and troubleshoot potential performance issues.
- Examine your application's Apache logs, which include a
request_timefield that indicates how many microseconds it takes to deliver each page of your application. Examine the Drupal request logs and look for requests with a long
queue_waitvalue. You can stream the Drupal request log in real time or download the Drupal request log from the Acquia Cloud interface Logs page. See About Acquia Cloud logging and Streaming log entries in real time.
- To view page delivery performance details, use the Drupal Performance logging features in the Devel module. Only use Devel for applications in non-production environments.