Development

“Maximum execution time exceeded” — how to fix it in WordPress

The message Fatal error: Maximum execution time of 30 seconds exceeded means a single PHP script took longer than the server allows and was stopped mid-run. Sometimes that limit is genuinely too low for the job; often it is a warning that something is far too slow.

What is really happening

PHP caps how long any one script may run so a runaway process cannot tie up the server. Thirty seconds is a common default. A big import, a full backup or a bulk operation can legitimately need more. But a normal page load hitting the limit is not a limit problem — it is a performance problem wearing a limit’s clothes.

Raise the limit (where it is warranted)

For a one-off import or migration, lift the ceiling using whichever you can access:

  • php.ini: max_execution_time = 300
  • .htaccess (Apache): php_value max_execution_time 300
  • wp-config.php: set_time_limit(300);

Managed hosts often set this in the control panel and ignore file overrides — check there or ask support. Raise it for the task, then put it back.

Fix the slow operation, do not just extend the clock

If ordinary front-end or admin pages are timing out, more seconds only hides it. Find the cause:

  • An unindexed or badly written database query — use Query Monitor to spot it.
  • A plugin making slow external API calls on every page load.
  • An oversized cron job piling up because it never finishes.

For imports and long jobs

When the job genuinely is long — migrating thousands of products, importing a large dataset — use a tool built to run in batches (WP-CLI, or an importer with chunked processing) rather than one long request. Batching sidesteps the timeout entirely instead of fighting it.