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
SetEnvIf directives. (The rewrite flag is preferred for controlling a single account. The
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:
importbuddy.phponly combined with
SetEnvIf Request_URI "(wp-cron|backupbuddy|importbuddy)\.php" noabort noconntimeout
RewriteRule .* - [E=noconntimeout:1]
RewriteRule (wp-cron|backupbuddy|importbuddy)\.php - [E=noconntimeout:1]
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
noabort is a LiteSpeed-specific environment variable, so all of the following rules should be placed in
[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:
SetEnvcan go anywhere in the config file.
SetEnvIfdirective should be used.
SetEnv noabort 1
SetEnvIf Request_URI "(wp-cron|backupbuddy|importbuddy)\.php" noabort
RewriteEngine On RewriteRule .* - [E=noabort:1]
RewriteEngine On RewriteRule (wp-cron|backupbuddy|importbuddy)\.php - [E=noabort:1]