Setting PHP without timeout

andych

Well-Known Member
#1
How do we do this?

Because I had a lots of 500 and 503 Internal Server Errors, so I want LS to allow PHP running indefinitely.

Because my PHP apps had a lots of processing time (e.g.: doing MySQL Maintenances, etc)



I don't have any clue how to set this (I mean the values to change)
 

webizen

Well-Known Member
#2
Admin CP = LiteSpeed Web Admin Console.

php.ini = php.ini file used by LSPHP. In general, you run from command line to find it.

/usr/local/lsws/fcgi-bin/lsphp5 -i| grep "Loaded Configuration"
 

andych

Well-Known Member
#3
I set:
Code:
max_execution_time = 900
in php.ini but PHP apps still killed at 45 secs.

It returns me the following error page:
Request Timeout

This request takes too long to process, it is timed out by the server. If it should not be timed out, please contact administrator of this web site to increase 'Connection Timeout'.
 

NiteWave

Administrator
#8
what's your web server's setting:
Server->Tuning->Connection Timeout (secs)

Server->External App->lsphp5
Initial Request Timeout (secs)
Connection Keepalive Timeout
 

andych

Well-Known Member
#9
Server->Tuning->Connection Timeout (secs) => 45
Server->External App->lsphp5->Initial Request Timeout (secs) => 60
 
#15
Thanks for prompt response.

I am aware of PHP max execution time and how to use it.

Wondering if we can set LSAPI_MAX_PROCESS_TIME value using PHP or HTaccess?
 
#17
Great Thank you.

Here is what i am trying to accomplish.

I have two scripts.

First Script:

PHP:
<?php
        $time_start = microtime(true);
        $url = 'http://www.domain.com/testing/persistent/asyncUrl.php';
        function makeAsyncCall($url, $params)
        {
            ini_set("default_socket_timeout", 10000);
            $post_string = http_build_query($params);
            $parts = parse_url($url);

            $fp = pfsockopen($parts['host'],
                    isset($parts['port']) ? $parts['port'] : '80',
                    $errno, $errstr, 30); // Here 30 is The connection timeout, in seconds.
            if(!$fp) {
                //Perform a synchronous call when the fsockopen function not supported / return error by the server
                echo "Error No: {$errno} <br/>";
                echo "And Error Message is: {$errstr}";
            } else {
                # stream_set_timeout($fp, 2500, 1000);
                $out  = "POST " . $parts['path'] . " HTTP/1.1\r\n";
                $out .= "Host: " . $parts['host'] . "\r\n";
                $out .= "Content-Type: application/x-www-form-urlencoded\r\n";
                $out .= "Content-Length: " . strlen($post_string) . "\r\n";
                # $out .= "Connection: Close\r\n";
                $out .= "Connection: Keep-Alive\r\n";
                $out .= "Keep-Alive:  timeout=190, max=100\r\n";
                $out .= "\r\n";

                if (isset($post_string)) {
                        $out .= $post_string;
                }

                fwrite($fp, $out);
                fclose($fp);
            }
        }
    //Define the post variables that you want sent
    $post_vars = array('customerId' => '36');
    $asyncUrl = 'http://www.domain.com/testing/persistent/asyncUrl.php';
  
    makeAsyncCall($asyncUrl, $post_vars);
      
    $time_end = microtime(true);
    echo '<b>Total Execution Time:</b> ' . ($time_end - $time_start) . ' Seconds';
?>

Second Script: asyncUrl.php

PHP:
<?php
try {
   $errorLog = time() . ".log";
   set_time_limit(0);
   ini_set('display_errors', '1');
   error_reporting(E_ALL);
   $timeStart = microtime(true);
   $count = 0;
   while($count < 300) {
     sleep(1);
     $count++;
     $timeEnd = microtime(true);
     $meesage = 'Total Execution Time - ' . $count. ': ' . ($timeEnd - $timeStart) . ' Seconds \n';
    
     error_log($meesage, 3, $errorLog);
   }
  
   $timeEnd = microtime(true);
   $meesage = 'Total Execution Time: ' . ($timeEnd - $timeStart) . ' Seconds \n';
   error_log($meesage, 3, $errorLog);

} catch (Exception $e) {
   echo "Error: " . $e->getMessage();  
   error_log("Error: " .$e->getMessage(), 3, $errorLog);
}
?>
HtAccess Code:
Code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /testing/persistent/
RewriteRule .* - [E=noconntimeout:1]
RewriteRule .* - [E=noabort:1]
</IfModule>

<IfModule litespeed>
RewriteRule .* - [E=noabort:1]
</IfModule>
First script will trigger the second script using pfsockopen and close the file pointer. My expectation is the second script to be executed for 300 seconds without any issue.

But the second script execution automatically stopped after X seconds (X = 45, 53, 60, 90 etc.,) and it is inconsistent execution time.

Note: The same script is working fine till 1000 seconds on both Apache & NGiNX but not Litespeed.

Any thoughts on why litespeed terminating the connections.
 

mistwang

LiteSpeed Staff
#18
Access your second script directly from a browser see if it can execute for 300 seconds.
If it can, the timeout is with the first script.

Maybe full debug logging will be helpful.
 
#19
You are right, when i access the second script directly from a browser then it execute for 300 seconds and no issue at all.

The issue only when the second URL triggered by first script.

Please let me know if you want me to share the original URLs to the scripts.
 
Top