Max execution time is a configured upper limit on how long a single script or request may run before the interpreter or server terminates it. In PHP the setting is called max_execution_time, and similar ceilings exist in web servers, application servers, FastCGI process managers and reverse proxies. Within the management of server resources, it acts as a safety valve that keeps one slow or looping request from holding a worker, CPU time and memory indefinitely.
The limit matters most on shared and multi-tenant servers, where a single runaway script can starve other sites of workers. It is closely related to the PHP memory limit and to process limits, but it measures time rather than space, and its exact meaning depends on which layer enforces it.
How max execution time stops a running script
Max execution time works by starting a timer when a request begins and aborting the script once the timer passes the configured threshold. In PHP the interpreter checks the timer periodically and raises a fatal error with the message “Maximum execution time of N seconds exceeded”, after which shutdown functions run and the worker returns to the pool.
A detail that surprises many administrators is what the PHP timer actually counts. On Linux and other Unix-like systems, max_execution_time measures CPU time consumed by the script itself, not wall-clock time. Time spent waiting on database queries, sleep() calls, file reads or outbound HTTP requests is usually not counted. On Windows the same setting measures wall-clock time, so identical code can behave differently across platforms.
Because of this, a script stuck waiting on a slow external API may run far longer than max_execution_time suggests. Other layers then become the effective limit: the FastCGI request timeout, the web server proxy timeout or the load balancer idle timeout. The following table shows the main enforcement points and what each one measures.
| Layer | Typical setting | What it measures | Common default |
|---|---|---|---|
| PHP interpreter | max_execution_time | CPU time on Unix, wall time on Windows | 30 seconds (0 on the command line) |
| PHP-FPM pool | request_terminate_timeout | Wall-clock time per request | 0 (disabled) |
| Nginx proxy | fastcgi_read_timeout | Wait between reads from the backend | 60 seconds |
| Apache | Timeout and ProxyTimeout | Wait for network activity | 60 seconds |
| Load balancer | Idle timeout | Inactivity on the connection | About 60 seconds on many platforms |
In practice the shortest limit in the chain wins. If PHP allows 300 seconds but the proxy closes the connection after 60, the visitor sees a 504 Gateway Timeout while the script may keep running in the background until its own limit expires.
Typical values and how they are configured
Appropriate values for max execution time depend on the type of workload, not on a single universal number. Interactive web pages should finish in well under a second, so a ceiling of 30 to 60 seconds already leaves a wide margin, while import jobs, report generation or backups may legitimately need several minutes.
| Workload | Typical limit | Reason |
|---|---|---|
| Public web pages | 30 seconds | Slow pages indicate a fault, not normal work |
| Administrative dashboards | 60 to 120 seconds | Occasional heavy queries and exports |
| Data imports and exports | 300 to 900 seconds | Large files processed in one request |
| Command-line jobs | 0 (unlimited) | Supervised by cron or a job runner instead |
| API endpoints | 10 to 30 seconds | Clients usually time out earlier |
The value can be set in several places. Server-wide defaults live in php.ini, per-pool values in the PHP-FPM pool file, per-directory values in .htaccess or .user.ini files, and per-script values through set_time_limit() or ini_set(). Note that `set_time_limit()` restarts the timer from zero rather than adding to elapsed time, and hosting providers often lock the setting so that customers cannot raise it beyond the plan ceiling.
How it relates to other server resource limits
Max execution time is one of several complementary guardrails that together keep a server stable. Each limit protects a different resource, and a well-tuned configuration aligns them so that the intended limit triggers first and produces a clear error.
| Limit | Resource protected | Typical symptom when hit |
|---|---|---|
| Max execution time | Worker time and CPU | Fatal error about exceeded execution time |
| PHP memory limit | Memory per script | Fatal error about exhausted memory |
| Process limit | Number of concurrent processes | Requests queue or are refused |
| Entry processes | Concurrent connections per account | Error 508 on CloudLinux hosts |
| CPU throttling | CPU share per account | Slower responses, no hard error |
These limits interact. A script that runs for a long time also occupies an entry process and a PHP-FPM worker, so a handful of slow requests can exhaust the process pool long before CPU utilization looks alarming. Conversely, CPU throttling on a shared host makes scripts slower, which can push borderline jobs over their execution time ceiling.
Choosing and tuning the limit
The right approach is to set max execution time as tight as normal traffic allows and to move genuinely long work out of the web request. Raising the limit to hide a slow script treats the symptom and leaves the worker pool exposed to the next spike.
| Situation | Recommended action | Why |
|---|---|---|
| Page occasionally exceeds 30 seconds | Profile queries and add indexes | The cause is usually inefficient code |
| Large import in the browser | Split into batches or a background job | Avoids proxy and browser timeouts |
| Nightly maintenance task | Run from the command line with cron | CLI has no default time ceiling |
| Slow third-party API | Set explicit HTTP client timeouts | PHP CPU timer may not count waiting |
| Proxy returns 504 first | Align proxy and FPM timeouts | The shortest limit hides the real error |
A sound rule is to keep the layers ordered from inner to outer: PHP limit shortest, then the PHP-FPM request_terminate_timeout, then the proxy timeout, then the load balancer. With this ordering the application produces a logged, explainable error instead of an anonymous gateway timeout.
Limitations and common mistakes
Max execution time is a coarse instrument and has several well-known blind spots that administrators should account for.
- Waiting time is often invisible: on Unix the PHP timer ignores time spent in database calls and network I/O, so it does not protect against slow dependencies.
- Setting the value to 0 removes the ceiling entirely and lets a stuck request hold a worker until a restart.
- Abrupt termination can leave partial writes, half-processed batches or stale locks unless the code uses transactions and shutdown handlers.
- Raising the limit globally for one slow plugin weakens protection for every site on the server.
- Ignoring outer timeouts leads to scripts that keep running after the visitor has already received an error.
Monitoring helps close these gaps. Tracking slow request logs in PHP-FPM, response time percentiles and the count of timeout errors shows whether the limit is protecting the server or merely masking a deeper performance problem.
A non-technical view
Think of a server as a restaurant kitchen with a fixed number of cooks. Each visitor request is an order, and each cook can handle only one order at a time. Max execution time is a rule that says no single order may occupy a cook for longer than a set time. If a dish takes too long, the cook stops and moves on.
This rule protects everyone else waiting for food. Without it, one complicated or broken order could tie up a cook all evening. The key point is that the limit protects shared capacity, so very long tasks are better prepared separately, outside the normal rush.
A concrete example
An online shop on a managed PHP host lets staff upload product catalogs of about 40,000 rows through an administration page. With max_execution_time set to 60 seconds and an Nginx fastcgi_read_timeout of 60 seconds, uploads regularly fail halfway, leaving some products updated and others not.
The administrator first considers raising both limits to 600 seconds, but that would let any slow page hold a worker for ten minutes. Instead, the upload page now stores the file and queues a background job processed by a command-line worker in batches of 500 rows, each inside a database transaction.
The web limits stay at 60 seconds for every page, imports finish in about four minutes without errors, and the shop no longer suffers from exhausted PHP-FPM workers during catalog updates.