PHP Timeout: max_execution_time
Configure PHP timeouts correctly.
PHP has a default execution limit of 30 seconds. Beyond that, the script is killed. For long operations (imports, exports, PDF generation), you need to adjust this limit.
Symptoms
- "Maximum execution time exceeded" error
- White page on long operations
- Imports/exports that fail
- Timeout without visible error message
Common Causes
- max_execution_time too short: Default value (30s) is insufficient.
- Poorly optimized script: Code does too many operations or inefficient loops.
- Slow external dependency: Third-party API or DB responding slowly.
Diagnostic Steps
- Check PHP logs for "Maximum execution time"
- Identify the concerned script
- Measure execution time with microtime()
- Profile code to find the bottleneck
Automate with MoniTao
MoniTao detects PHP timeouts:
- Endpoint monitoring with configurable timeout
- Alerts on 500 errors (fatal timeout)
- Heartbeat for background scripts
Best Practices
- Put long operations in background (queue)
- Use set_time_limit() for specific scripts
- Align PHP timeouts with Nginx/Apache
- Implement progress indicators for UX
FAQ
How to increase max_execution_time?
In php.ini, via .htaccess, or set_time_limit() in code.
Can I set 0 (infinite)?
Technically yes, but it's risky. Prefer a high value (300s).
Does set_time_limit reset the timer?
Yes, calling set_time_limit(30) restarts from zero.
How to monitor long scripts?
Use MoniTao heartbeat: the script pings before and after.
Useful Links
Ready to Sleep Soundly?
Start free, no credit card required.