Setting PHP without timeout

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

  1. andych

    andych Well-Known 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)


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

    webizen Well-Known 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 Well-Known Member

    I set:
    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 Well-Known 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 Well-Known 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 Well-Known Member

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

    NiteWave Administrator

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

    try to increase it
  11. Kiran

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

    Great Thank you.

    Here is what i am trying to accomplish.

    I have two scripts.

    First Script:

    $url '';
    $post_string http_build_query($params);
    $parts parse_url($url);

    $fp pfsockopen($parts['host'],
    $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/>";
    "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;

    //Define the post variables that you want sent
    $post_vars = array('customerId' => '36');
    $asyncUrl '';
    $time_end microtime(true);
    '<b>Total Execution Time:</b> ' . ($time_end $time_start) . ' Seconds';

    Second Script: asyncUrl.php

    try {
    $errorLog time() . ".log";
    $timeStart microtime(true);
    $count 0;
    $count 300) {
    $timeEnd microtime(true);
    $meesage 'Total Execution Time - ' $count': ' . ($timeEnd $timeStart) . ' Seconds \n';
    $timeEnd microtime(true);
    $meesage 'Total Execution Time: ' . ($timeEnd $timeStart) . ' Seconds \n';

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