Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Need longer timeouts in PHP

  1. #1
    King Tutorial-ankhamun
    Join Date
    Jul 2004
    Posts
    897

    Need longer timeouts in PHP

    Hi all,
    I'm working on a PHP script that takes a long time to run, I set up my PHP.ini with the following lines:

    max_execution_time = 3000 ; Maximum execution time of each script, in seconds
    max_input_time = 3000 ; Maximum amount of time each script may spend parsing request data
    memory_limit = 208M ; Maximum amount of memory a script may consume (8MB)

    I then restart Apache, but it still seems to time out well before the limit I set. Any ideas?

  2. #2
    Senior Member
    Join Date
    Mar 2002
    Posts
    502
    I think this is caused by Apache's timeout value in the httpd.conf file. Make sure it's more than or equal to the max_execution_time value in your php.ini file.
    Bleh.

  3. #3
    King Tutorial-ankhamun
    Join Date
    Jul 2004
    Posts
    897
    Do you know what the option is called? It currently is set as:

    Code:
    #
    # Timeout: The number of seconds before receives and sends time out.
    #
    Timeout 300
    but it times out way before 5 min.

  4. #4
    Senior Member
    Join Date
    Mar 2002
    Posts
    502
    That's the option I'm talking about. Does the code use any sleep() functions or something similar, PHP's way of counting execution time is weird with that.
    Bleh.

  5. #5
    King Tutorial-ankhamun
    Join Date
    Jul 2004
    Posts
    897
    Nope, what I have of the script is posted below:

    Code:
    <?php   
    header("Content-type: text/html");
    echo "<PRE>";
    echo find_os();
    echo find_browser();
    echo whois_info();
    echo netbios_info();
    echo nmap_info();
    
    function whois_info(  )
    {
    	$results =shell_exec("whois ".$_SERVER['REMOTE_ADDR']);
    	return $results;
    }
    
    
    
    function netbios_info(  )
    {
    	$results =shell_exec("nmblookup -A  ".$_SERVER['REMOTE_ADDR']);
    
    	return $results;
    }
    
    function nmap_info(  )
    {
    	$results =shell_exec("nmap -sS -O -P0 -A -T insane  ".$_SERVER['REMOTE_ADDR']);
    
    	return $results;
    }
    
    
    function find_os()
    {
    $browserarray=explode("; ",$_SERVER['HTTP_USER_AGENT']);
    $os= $browserarray[2];  
    return $os;
    }
    
    function find_browser()
    {
    $browserarray=explode("; ",$_SERVER['HTTP_USER_AGENT']);
    if ($browserarray[1]=="U"){
    	$browser = $browserarray[4];
    }else {
    	$browser = $browserarray[1];
    }
    return $browser;
    }
    
    ?>
    By the way, thanks foir the help.

  6. #6
    Senior Member
    Join Date
    Mar 2002
    Posts
    502
    PHP doesn't include the time spend on external programs (whois, nmblookup, and nmap in your case) when calculating the execution time. Setting the php.ini max_execution_time setting and the httpd.conf TimeOut directive to a high value should give you a lot of time to work with though. Let me know if it works or not.
    Bleh.

  7. #7
    King Tutorial-ankhamun
    Join Date
    Jul 2004
    Posts
    897
    I did the changes, and it still times out in about 20 sec or so.

  8. #8
    Senior Member
    Join Date
    Mar 2002
    Posts
    502
    Does it also timeout early with something like this:
    Code:
    <?php
    
    $i = 1;
    while ($i > 0)
    {
    	echo($i . ' ');
    	$i++;
    }
    
    ?>
    Bleh.

  9. #9
    King Tutorial-ankhamun
    Join Date
    Jul 2004
    Posts
    897
    Nope, it just keeps going an going.

  10. #10
    Senior Member
    Join Date
    Mar 2002
    Posts
    502
    Then I think it's because you're using shell_exec(). This is what php.net says about it here:
    The set_time_limit() function and the configuration directive max_execution_time only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), stream operations, database queries, etc. is not included when determining the maximum time that the script has been running.
    I'm afraid there's nothing that can be done about it. If you really want to do this, you could try writing PHP versions of the programs you're calling with shell_exec().
    Bleh.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •