Some PHP scripts need to run for long periods of time without interruption. Examples include WordPress modules such as BackupBuddy, ImportBuddy, or any other module that relies on a WordPress built-in cron job. Whenever a PHP application rebuilds MySQL indexes, the process may run for a long time.
Generally, allowing a PHP script to run forever is not desirable. Thus there are a number of features (in LiteSpeed Web Server and built into PHP itself) that may prevent a PHP process from running long enough to finish. You may need to set up more than one of the following configurations to ensure your application works correctly.
Override LiteSpeed Connection Timeout
If a script does not send back anything for a long time, this can trigger a connection timeout, and the server will close the client connection. This is done to prevent poorly written PHP scripts from tying up the server. To get desired functionality from your web applications, though, you may need to prevent the connection from being timed out. (If the noabort
environment variable above has been set, the script will continue to run even though the connection has been broken. Your application, though, may require the connection to stay open for correct functionality.)
Connection timeout can be prevented by either increasing the global connection timeout setting (via the WebAdmin console) or using LiteSpeed's noconntimeout
environment variable.
Similar to the noabort
environment variable, you can add the noconntimeout
environment variable via a rewrite rule or using the SetEnv
/SetEnvIf
directives. (The rewrite flag is preferred for controlling a single account. The SetEnv
/SetEnvIf
directives are preferred for rules that will apply to all accounts.) noconntimeout
is a LiteSpeed-specific environment variable, so all of the following examples should be placed inside:
<IfModule Litespeed>
...
</IfModule>
Directive example for wp-cron.php
, backupbuddy.php,
and importbuddy.php
only combined with noabort
SetEnvIf Request_URI "(wp-cron|backupbuddy|importbuddy)\.php" noabort noconntimeout
Rewrite rule example for all requests
RewriteEngine On
RewriteRule .* - [E=noconntimeout:1]
Rewrite rule example for wp-cron.php
, backupbuddy.php,
and importbuddy.php
only
RewriteRule (wp-cron|backupbuddy|importbuddy)\.php - [E=noconntimeout:1]
Rewrite rule example combined with noabort
RewriteRule (wp-cron|backupbuddy|importbuddy)\.php - [E=noabort:1, E=noconntimeout:1]
Turn off Broken Connection Aborting
When a user closes a connection (by closing a window, for example), LSWS will abort processing that PHP script by killing the PHP process. This is to avoid wasting system resources and to prevent certain types of DoS attacks.
In some cases, though, it is preferable not to abort the PHP script, regardless of whether the connection has been closed. For example, built-in WordPress Cron jobs start a background job by sending a request to wp-cron.php
, then immediately closing the connection without waiting for a response. In order for the cron job to complete, though, the webserver must keep the PHP engine running without interruption.
In this case, you need to turn off broken connection aborting. This be done at the server level in LSWS's WebAdmin Console or by using LiteSpeed's noabort
environment variable.
Aborting for a broken connection can be turned off by using the request-level noabort
environment variable. This can be done in a rewrite rule or by using the SetEnv
/SetEnvIf
directives. noabort
is a LiteSpeed-specific environment variable, so all of the following rules should be placed in
<IfModule Litespeed>
...
</IfModule>
The [E=noabort:1]
the flag can be added to any rewrite rule. The rewrite rule can be in an Apache .htaccess
file or host-level configuration file. The rewrite flag should generally be used for a single account only.
Rewrite rules and SetEnv
should not be used together. We recommend choosing the SetEnv
directive over rewrite rules for two reasons:
- Rewrite rules are sensitive to a position among the other rules.
SetEnv
can go anywhere in the config file. - Rewrite rules cannot be easily inherited. To impact all accounts with one setting, the
SetEnvIf
the directive should be used.
Directive example for all requests
SetEnv noabort 1
Directive example for wp-cron.php
, backupbuddy.php,
and importbuddy.php
only
SetEnvIf Request_URI "(wp-cron|backupbuddy|importbuddy)\.php" noabort
Rewrite rule example for all requests
RewriteEngine On RewriteRule .* - [E=noabort:1]
Rewrite rule example for wp-cron.php
, backupbuddy.php,
and importbuddy.php
only
RewriteEngine On RewriteRule (wp-cron|backupbuddy|importbuddy)\.php - [E=noabort:1]