Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
litespeed_wiki:php:run-without-timeouts [2015/07/28 18:50]
Michael Alegre created
litespeed_wiki:php:run-without-timeouts [2019/06/06 18:49] (current)
Lisa Clarke [Troubleshooting ] Proofreading
Line 28: Line 28:
 ==== Through the "​noabort"​ environment variable ==== ==== Through the "​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 using the SetEnv/​SetEnvIf directives. "​noabort"​ is a LiteSpeed-specifc ​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 using the SetEnv/​SetEnvIf directives. "​noabort"​ is a LiteSpeed-specific ​environment variable, so all 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 usually be used for a single account only. If you need to do a server-level configuration that will apply to all accounts (though perhaps only for certain scripts), you should use the SetEnvIf directive. ​ 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 usually be used for a single account only. If you need to do a server-level configuration that will apply to all accounts (though perhaps only for certain scripts), you should use the SetEnvIf directive. ​
Line 68: Line 71:
  
 This setting can be increased to allow scripts to run longer (though they will still time out after the specified time has elapsed). This setting can be increased to allow scripts to run longer (though they will still time out after the specified time has elapsed).
 +
 +If LiteSpeed ADC is running in front , ADC connection timeout also need to adjust.
  
 ==== Through "​noconntimeout"​ environment variable ==== ==== Through "​noconntimeout"​ environment variable ====
  
-Similarly 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-specifc environment variable.+Similarly 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-specifc environment variable, so all the following examples should be placed inside: 
 +  <​IfModule Litespeed>​  
 +  ​... 
 +  </​IfModule>​
  
 === Rewrite rule examples: === === Rewrite rule examples: ===
Line 141: Line 149:
  
 **Note:** You need to turn off keepalive connections for this request. This can be done with a rewrite rule. **Note:** You need to turn off keepalive connections for this request. This can be done with a rewrite rule.
 +
 +===== Troubleshooting =====
 +
 +==== "​noabort"​ rule should be placed at the top of the .htaccess ====
 +A ''​test.php''​ script sets sleep time to 320 seconds, like so:
 +
 +<​code>​
 +?php
 +
 +//Store the micro time so that we know
 +//when our script started to run.
 +$executionStartTime = microtime(true);​
 +
 +// displaying time
 +echo date('​h:​i:​s'​)."​\n"​ ;
 +
 +// delaying execution of the script for 2 seconds
 +sleep(320);
 +
 +// displaying time again
 +echo date('​h:​i:​s'​);​
 +
 +//At the end of your code, compare the current
 +//microtime to the microtime that we stored
 +//at the beginning of the script.
 +$executionEndTime = microtime(true);​
 +
 +//The result will be in seconds and milliseconds.
 +$seconds = $executionEndTime - $executionStartTime;​
 +
 +//Print it out
 +echo "This script took $seconds to execute.";​
 +?>
 +</​code>​
 +
 +When it is run, however, it errors out and stops at 300 seconds (5 minutes). ''​phpinfo.php''​ shows **max_exectution_time** is ''​600''​. The script times out due to LiteSpeed Web Server'​s default 300-second timeout. The default, however, can be overridden by a ''​noabort''​ or ''​noconntimeout''​ rule. 
 +
 +In this example, ''​.htaccess''​ //does// have a ''​noabort''​ rule, but the test script still stops at 300 seconds:
 +
 +<​code>​
 +Oct8ne
 +                <​IfModule mod_rewrite.c>​
 +                RewriteEngine on
 +                RewriteRule ^oct8ne/​frame/​([a-zA-Z]+)$ index.php?​fc=module&​module=oct8ne&​controller=oct8neconnector&​octmethod=$1&​%{QUERY_STRING} [QSA,L]
 +                </​IfModule>​
 +                #End_Oct8ne
 +                # ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
 +# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution
 +# http://​www.prestashop.com - http://​www.prestashop.com/​forums
 +
 +<​IfModule mod_rewrite.c>​
 +<​IfModule mod_env.c>​
 +SetEnv HTTP_MOD_REWRITE On
 +</​IfModule>​
 +
 +RewriteEngine on
 +
 +#
 +RewriteRule . - [E=REWRITEBASE:/​]
 +RewriteRule ^api$ api/ [L]
 +
 +RewriteRule ^api/(.*)$ %{ENV:​REWRITEBASE}webservice/​dispatcher.php?​url=$1 [QSA,L]
 +
 +# Images
 +RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?​(-[0-9]+)?/​.+\.jpg$ %{ENV:​REWRITEBASE}img/​p/​$1/​$1$2$3.jpg [L]
 +RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?​(-[0-9]+)?/​.+\.jpg$ %{ENV:​REWRITEBASE}img/​p/​$1/​$2/​$1$2$3$4.jpg [L]
 +RewriteRule ^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?​(-[0-9]+)?/​.+\.jpg$ %{ENV:​REWRITEBASE}img/​p/​$1/​$2/​$3/​$1$2$3$4$5.jpg [L]
 +RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?​(-[0-9]+)?/​.+\.jpg$ %{ENV:​REWRITEBASE}img/​p/​$1/​$2/​$3/​$4/​$1$2$3$4$5$6.jpg [L]
 +RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?​(-[0-9]+)?/​.+\.jpg$ %{ENV:​REWRITEBASE}img/​p/​$1/​$2/​$3/​$4/​$5/​$1$2$3$4$5$6$7.jpg [L]
 +RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?​(-[0-9]+)?/​.+\.jpg$ %{ENV:​REWRITEBASE}img/​p/​$1/​$2/​$3/​$4/​$5/​$6/​$1$2$3$4$5$6$7$8.jpg [L]
 +RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?​(-[0-9]+)?/​.+\.jpg$ %{ENV:​REWRITEBASE}img/​p/​$1/​$2/​$3/​$4/​$5/​$6/​$7/​$1$2$3$4$5$6$7$8$9.jpg [L]
 +RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?​(-[0-9]+)?/​.+\.jpg$ %{ENV:​REWRITEBASE}img/​p/​$1/​$2/​$3/​$4/​$5/​$6/​$7/​$8/​$1$2$3$4$5$6$7$8$9$10.jpg [L]
 +RewriteRule ^c/​([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/​.+\.jpg$ %{ENV:​REWRITEBASE}img/​c/​$1$2$3.jpg [L]
 +RewriteRule ^c/​([a-zA-Z_-]+)(-[0-9]+)?/​.+\.jpg$ %{ENV:​REWRITEBASE}img/​c/​$1$2.jpg [L]
 +# AlphaImageLoader for IE and fancybox
 +RewriteRule ^images_ie/?​([^/​]+)\.(jpe?​g|png|gif)$ js/​jquery/​plugins/​fancybox/​images/​$1.$2 [L]
 +
 +# Dispatcher
 +RewriteCond %{REQUEST_FILENAME} -s [OR]
 +RewriteCond %{REQUEST_FILENAME} -l [OR]
 +RewriteCond %{REQUEST_FILENAME} -d
 +RewriteRule ^.*$ - [NC,L]
 +RewriteRule ^.*$ %{ENV:​REWRITEBASE}index.php [NC,L]
 +
 +AddType application/​vnd.ms-fontobject .eot
 +AddType font/ttf .ttf
 +AddType font/otf .otf
 +AddType font/woff2 .woff2
 +AddType application/​x-font-woff .woff
 +<​IfModule mod_headers.c>​
 +        <​FilesMatch "​\.(ttf|ttc|otf|eot|woff|woff2|svg)$">​
 +                Header set Access-Control-Allow-Origin "​*"​
 +        </​FilesMatch>​
 +</​IfModule>​
 +
 +#If rewrite mod isn't enabled
 +ErrorDocument 404 /​index.php?​controller=404
 +
 +# ~~end~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
 +
 +# # BEGIN litespeed noconntimeout noabort
 +<​IfModule Litespeed>​
 + ​RewriteEngine On
 + ​RewriteRule .* - [E=noabort:​1]
 +</​IfModule>​
 +# # END litespeed noconntimeout noabort
 +
 +# php -- BEGIN cPanel-generated handler, do not edit
 +# Set the “ea-php70” package as the default “PHP” programming language.
 +<​IfModule mime_module>​
 +  AddHandler application/​x-httpd-ea-php70 .php .php7 .phtml
 +</​IfModule>​
 +# php -- END cPanel-generated handler, do not edit
 +
 +# BEGIN cPanel-generated php ini directives, do not edit
 +# Manual editing of this file may result in unexpected behavior.
 +# To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
 +# For more information,​ read our documentation (https://​go.cpanel.net/​EA4ModifyINI)
 +<​IfModule php7_module>​
 +   ​php_flag display_errors Off
 +   ​php_value max_execution_time 600
 +   ​php_value max_input_time 600
 +   ​php_value max_input_vars 6000
 +   ​php_value memory_limit 1024M
 +   ​php_value post_max_size 1024M
 +   ​php_value session.gc_maxlifetime 1440
 +   ​php_value session.save_path "/​var/​cpanel/​php/​sessions/​ea-php73"​
 +   ​php_value upload_max_filesize 1024M
 +   ​php_flag zlib.output_compression Off
 +</​IfModule>​
 +<​IfModule lsapi_module>​
 +   ​php_flag display_errors Off
 +   ​php_value max_execution_time 600
 +   ​php_value max_input_time 600
 +   ​php_value max_input_vars 6000
 +   ​php_value memory_limit 1024M
 +   ​php_value post_max_size 1024M
 +   ​php_value session.gc_maxlifetime 1440
 +   ​php_value session.save_path "/​var/​cpanel/​php/​sessions/​ea-php73"​
 +   ​php_value upload_max_filesize 1024M
 +   ​php_flag zlib.output_compression Off
 +</​IfModule>​
 +# END cPanel-generated php ini directives, do not edit
 +</​code>​
 +
 +The problem is the position of the ''​noabort''​ rule. it was placed nearly at the end of ''​.htaccess'',​ and as such, it is prevented from being executed by the other rules that come before it.  ​
 + ​RewriteRule .* - [E=noabort:​1]
 +
 +Move the rule to the very top of all ''​.htaccess''​ rewrite rules, and the test script will no longer time out.
  • Admin
  • Last modified: 2015/07/28 18:50
  • by Michael Alegre