{"id":112,"date":"2022-05-10T14:40:54","date_gmt":"2022-05-10T14:40:54","guid":{"rendered":"https:\/\/help.radia.cloud\/en\/?post_type=base-de-conocimieto&#038;p=112"},"modified":"2022-05-10T14:40:55","modified_gmt":"2022-05-10T14:40:55","slug":"execute-php-scripts-with-no-timeout-when-using-litespeed-2","status":"publish","type":"base-de-conocimieto","link":"https:\/\/help.radia.cloud\/en\/article\/execute-php-scripts-with-no-timeout-when-using-litespeed-2\/","title":{"rendered":"Execute PHP scripts with no timeout when using Litespeed"},"content":{"rendered":"\n<p>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.<\/p>\n\n\n\n<p><br>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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Override LiteSpeed Connection Timeout<\/h2>\n\n\n\n<p>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&nbsp;<code>noabort<\/code>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.)<\/p>\n\n\n\n<p>Connection timeout can be prevented by either increasing the global connection timeout setting (via the WebAdmin console) or using LiteSpeed&#8217;s&nbsp;<code>noconntimeout<\/code>&nbsp;environment variable.<\/p>\n\n\n\n<p>Similar to the&nbsp;<code>noabort<\/code>&nbsp;environment variable, you can add the&nbsp;<code>noconntimeout<\/code>&nbsp;environment variable via a rewrite rule or using the&nbsp;<code>SetEnv<\/code>\/<code>SetEnvIf<\/code>&nbsp;directives. (The rewrite flag is preferred for controlling a single account. The&nbsp;<code>SetEnv<\/code>\/<code>SetEnvIf<\/code>&nbsp;directives are preferred for rules that will apply to all accounts.)&nbsp;<code>noconntimeout<\/code>&nbsp;is a LiteSpeed-specific environment variable, so all of the following examples should be placed inside:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;IfModule Litespeed&gt; <br>... <br>&lt;\/IfModule&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Directive example for&nbsp;<code>wp-cron.php<\/code>,&nbsp;<code>backupbuddy.php,<\/code>&nbsp;and&nbsp;<code>importbuddy.php<\/code>&nbsp;only combined with&nbsp;<code>noabort<\/code><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>SetEnvIf Request_URI \"(wp-cron|backupbuddy|importbuddy)\\.php\" noabort noconntimeout<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><br>Rewrite rule example for all requests<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine On <br>RewriteRule .* - &#91;E=noconntimeout:1]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Rewrite rule example for&nbsp;<code>wp-cron.php<\/code>,&nbsp;<code>backupbuddy.php,<\/code>&nbsp;and&nbsp;<code>importbuddy.php<\/code>&nbsp;only<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteRule (wp-cron|backupbuddy|importbuddy)\\.php - &#91;E=noconntimeout:1]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Rewrite rule example combined with&nbsp;<code>noabort<\/code><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteRule (wp-cron|backupbuddy|importbuddy)\\.php - &#91;E=noabort:1, E=noconntimeout:1]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><br>Turn off Broken Connection Aborting<\/h2>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>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&nbsp;<code>wp-cron.php<\/code>, 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.<\/p>\n\n\n\n<p>In this case, you need to turn off broken connection aborting. This be done at the server level in LSWS&#8217;s WebAdmin Console or by using LiteSpeed&#8217;s&nbsp;<code>noabort<\/code>&nbsp;environment variable.<\/p>\n\n\n\n<p>Aborting for a broken connection can be turned off by using the request-level&nbsp;<code>noabort<\/code>&nbsp;environment variable. This can be done in a rewrite rule or by using the&nbsp;<code>SetEnv<\/code>\/<code>SetEnvIf<\/code>&nbsp;directives.&nbsp;<code>noabort<\/code>&nbsp;is a LiteSpeed-specific environment variable, so all of the following rules should be placed in<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;IfModule Litespeed&gt; <br>... <br>&lt;\/IfModule&gt;<\/code><\/pre>\n\n\n\n<p>The&nbsp;<code>[E=noabort:1]<\/code>&nbsp;flag can be added to any rewrite rule. The rewrite rule can be in an Apache&nbsp;<code>.htaccess<\/code>&nbsp;file or vhost-level configuration file. The rewrite flag should generally be used for a single account only.<\/p>\n\n\n\n<p>Rewrite rules and&nbsp;<code>SetEnv<\/code>&nbsp;should not be used together. We recommend choosing the&nbsp;<code>SetEnv<\/code>&nbsp;directive over rewrite rules for two reasons:<\/p>\n\n\n\n<ol><li>Rewrite rules are sensitive to a position among the other rules.&nbsp;<code>SetEnv<\/code>&nbsp;can go anywhere in the config file.<\/li><li>Rewrite rules cannot be easily inherited. To impact all accounts with one setting, the&nbsp;<code>SetEnvIf<\/code>&nbsp;directive should be used.<\/li><\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Directive example for all requests<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>SetEnv noabort 1<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><br>Directive example for&nbsp;<code>wp-cron.php<\/code>,&nbsp;<code>backupbuddy.php,<\/code>&nbsp;and&nbsp;<code>importbuddy.php<\/code>&nbsp;only<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>SetEnvIf Request_URI \"(wp-cron|backupbuddy|importbuddy)\\.php\" noabort<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><br>Rewrite rule example for all requests<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine On RewriteRule .* - &#91;E=noabort:1]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Rewrite rule example for&nbsp;<code>wp-cron.php<\/code>,&nbsp;<code>backupbuddy.php,<\/code>&nbsp;and&nbsp;<code>importbuddy.php<\/code>&nbsp;only<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine On RewriteRule (wp-cron|backupbuddy|importbuddy)\\.php - &#91;E=noabort:1]<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":""},"bdctema":[19],"bdcetiqueta":[20,21,24],"_links":{"self":[{"href":"https:\/\/help.radia.cloud\/en\/wp-json\/wp\/v2\/base-de-conocimieto\/112"}],"collection":[{"href":"https:\/\/help.radia.cloud\/en\/wp-json\/wp\/v2\/base-de-conocimieto"}],"about":[{"href":"https:\/\/help.radia.cloud\/en\/wp-json\/wp\/v2\/types\/base-de-conocimieto"}],"author":[{"embeddable":true,"href":"https:\/\/help.radia.cloud\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/help.radia.cloud\/en\/wp-json\/wp\/v2\/comments?post=112"}],"version-history":[{"count":1,"href":"https:\/\/help.radia.cloud\/en\/wp-json\/wp\/v2\/base-de-conocimieto\/112\/revisions"}],"predecessor-version":[{"id":114,"href":"https:\/\/help.radia.cloud\/en\/wp-json\/wp\/v2\/base-de-conocimieto\/112\/revisions\/114"}],"wp:attachment":[{"href":"https:\/\/help.radia.cloud\/en\/wp-json\/wp\/v2\/media?parent=112"}],"wp:term":[{"taxonomy":"bdctema","embeddable":true,"href":"https:\/\/help.radia.cloud\/en\/wp-json\/wp\/v2\/bdctema?post=112"},{"taxonomy":"bdcetiqueta","embeddable":true,"href":"https:\/\/help.radia.cloud\/en\/wp-json\/wp\/v2\/bdcetiqueta?post=112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}