Wednesday, May 21, 2008

Troubleshooting "Fatal error: Maximum execution time exceeded" in PHP

The "Fatal error: Maximum execution time of [some number] seconds exceeded in [php file name] on line [some number]" error message indicates that the called PHP script reach the time limit and was terminated by the PHP language engine. There are number of reasons for that and most common of them are:
  • Sending a lot of queries to a database.
  • Some particular database query requires a lot of time to complete.
  • Script has a lot of data to process.
  • Defect in script code.
If you are the script developer, you can profile it and fix bottlenecks. If you an administrator, you can try to increase PHP script time limit in PHP.ini by increasing the value of the max_execution_time option (in seconds) or call the set_time_limit function at the very top of the script in a PHP code block.

Examples:
  • PHP.INI: max_execution_time = 600
  • PHP script:
  • .htaccess: php_value max_execution_time 600

No comments: