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.
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>
wp-cron.php
, backupbuddy.php,
and importbuddy.php
only combined with noabort
SetEnvIf Request_URI "(wp-cron|backupbuddy|importbuddy)\.php" noabort noconntimeout
RewriteEngine On
RewriteRule .* - [E=noconntimeout:1]
wp-cron.php
, backupbuddy.php,
and importbuddy.php
onlyRewriteRule (wp-cron|backupbuddy|importbuddy)\.php - [E=noconntimeout:1]
noabort
RewriteRule (wp-cron|backupbuddy|importbuddy)\.php - [E=noabort:1, E=noconntimeout:1]
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 web server 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]
flag can be added to any rewrite rule. The rewrite rule can be in an Apache .htaccess
file or vhost-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:
SetEnv
can go anywhere in the config file.SetEnvIf
directive should be used.SetEnv noabort 1
wp-cron.php
, backupbuddy.php,
and importbuddy.php
onlySetEnvIf Request_URI "(wp-cron|backupbuddy|importbuddy)\.php" noabort
RewriteEngine On RewriteRule .* - [E=noabort:1]
wp-cron.php
, backupbuddy.php,
and importbuddy.php
onlyRewriteEngine On RewriteRule (wp-cron|backupbuddy|importbuddy)\.php - [E=noabort:1]