Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
litespeed_wiki:php:run-without-timeouts [2019/03/24 16:45]
qtwrk
litespeed_wiki:php:run-without-timeouts [2019/06/06 18:49] (current)
Lisa Clarke [Troubleshooting ] Proofreading
Line 149: 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: 2019/03/24 16:45
  • by qtwrk