Setting PHP without timeout

Discussion in 'Install/Configuration' started by andych, Jul 17, 2013.

  1. andych

    andych New Member

    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)

    [​IMG]

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

    webizen New Member

    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"
  3. andych

    andych New Member

    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:
  4. NiteWave

    NiteWave Administrator

    is your lsws version 4.2.3 ?
  5. andych

    andych New Member

    Yes, it is :)
  6. NiteWave

    NiteWave Administrator

    please try
    admin console->Server->General->External Application Abort:No Abort

    see if it helps.
  7. andych

    andych New Member

    still killed at 45th second.
  8. NiteWave

    NiteWave Administrator

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

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

    andych New Member

    Server->Tuning->Connection Timeout (secs) => 45
    Server->External App->lsphp5->Initial Request Timeout (secs) => 60
  10. NiteWave

    NiteWave Administrator

    look,
    Server->Tuning->Connection Timeout (secs) => 45
    match your magic 45 seconds issue :)

    try to increase it
  11. Kiran

    Kiran New Member

    Where can we find LSAPI_MAX_PROCESS_TIME value?
  12. mistwang

    mistwang LiteSpeed Staff

    You add it to the "environment" configuration for the external app. it was not set explicitly by default.
  13. Kiran

    Kiran New Member

    Is there a way to set this LSAPI_MAX_PROCESS_TIME value using PHP or HTaccess?
  14. mistwang

    mistwang LiteSpeed Staff

  15. Kiran

    Kiran New Member

    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?
  16. mistwang

    mistwang LiteSpeed Staff

  17. Kiran

    Kiran New Member

    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$errstr30); // 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($meesage3$errorLog);
       }
      
       
    $timeEnd microtime(true);
       
    $meesage 'Total Execution Time: ' . ($timeEnd $timeStart) . ' Seconds \n';
       
    error_log($meesage3$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.
  18. mistwang

    mistwang LiteSpeed Staff

    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. Kiran

    Kiran New Member

    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.
  20. NiteWave

    NiteWave Administrator

    what's current setting of lsphp5 -> Max Idle Time ?
    please try set it to 300 or 3600, any difference ?

Share This Page