Stop LiteSpeed cutting off long-running PHP scripts
Use the noabort and noconntimeout environment variables in .htaccess so backups, imports and WP-Cron finish instead of being killed part-way.
Some PHP scripts legitimately run for minutes — full-site backups, large imports, database index rebuilds, WP-Cron jobs. LiteSpeed stops long or silent requests by default, which can kill them mid-run. Applies to all shared and reseller hosting, which runs LiteSpeed.
Two separate protections cause this, and they need different fixes. Most long-running scripts need both.
| Variable | Stops LiteSpeed from | Needed when |
|---|---|---|
noabort | Killing PHP when the visitor's connection closes | The script is started and then abandoned, as WP-Cron does |
noconntimeout | Closing a connection that has sent nothing for too long | The script runs a long time before producing output |
Both are LiteSpeed-specific and must be wrapped in an IfModule block so the
rules are ignored on any other web server.
Set them in .htaccess
Add this to the .htaccess file in your site's document root:
<IfModule Litespeed>
SetEnvIf Request_URI "(wp-cron|backupbuddy|importbuddy)\.php" noabort noconntimeout
</IfModule>That targets the three scripts most often affected. Replace the names with whatever your own long-running script is called.
To apply it to every request on the site instead:
<IfModule Litespeed>
SetEnv noabort 1
SetEnv noconntimeout 1
</IfModule>Applying this to every request removes the protection that stops a runaway script consuming resources indefinitely. On shared hosting that counts against your account's limits. Target the specific scripts that need it.
Prefer SetEnv over rewrite rules
The same result can be achieved with rewrite flags:
<IfModule Litespeed>
RewriteEngine On
RewriteRule (wp-cron|backupbuddy|importbuddy)\.php - [E=noabort:1,E=noconntimeout:1]
</IfModule>Use SetEnv and SetEnvIf instead where you can. Rewrite rules are sensitive
to their position relative to other rules — WordPress's own rewrite block in
particular — so a rule placed after the WordPress block may never be reached.
SetEnv can go anywhere in the file.
Do not use both approaches for the same script.
PHP's own limit still applies
These variables control LiteSpeed. PHP has a separate limit, and a script can still be stopped by it:
max_execution_time = 300Set it in cPanel's MultiPHP INI Editor. See PHP versions and settings.
If a script stops at a consistent time — exactly 30 or exactly 60 seconds — that is almost always PHP's limit rather than LiteSpeed's.
Before you reach for this
A script needing several minutes is often a symptom rather than a requirement.
- WP-Cron is better replaced with a real cron job than kept alive. A system cron calling WP-CLI is more reliable and does not depend on a visitor arriving.
- Plugin backups write full copies of the site into your own disk quota, and are removed by WebGee's cleanup. Use JetBackup instead — see Files WebGee automatically removes.
Verify
Run the script and confirm it completes. If it still stops, check whether it
stops at a fixed time — that points at max_execution_time, not LiteSpeed.
Related
Improve a slow WordPress or WooCommerce dashboard
Find what is actually making wp-admin slow, then fix it — in the order that finds the cause fastest rather than a list of everything possible.
Optimise your WordPress database
Clear out post revisions, auto-drafts, spam and transients with the LiteSpeed Database Optimizer, and know which options are safe to run.