php timeout - set_time_limit(0); - don't work

前端 未结 5 1325
感动是毒
感动是毒 2020-12-15 04:25

I\'m having a problem with my PHP file that takes more than 30 seconds to execute.

After searching, I added set_time_limit(0); at the start of the code,

相关标签:
5条回答
  • 2020-12-15 04:28

    Check the php.ini

    ini_set('max_execution_time', 300); //300 seconds = 5 minutes
    
    ini_set('max_execution_time', 0); //0=NOLIMIT
    
    0 讨论(0)
  • 2020-12-15 04:38
    ini_set('max_execution_time', 300);
    

    use this

    0 讨论(0)
  • 2020-12-15 04:39

    I usually use set_time_limit(30) within the main loop (so each loop iteration is limited to 30 seconds rather than the whole script).

    I do this in multiple database update scripts, which routinely take several minutes to complete but less than a second for each iteration - keeping the 30 second limit means the script won't get stuck in an infinite loop if I am stupid enough to create one.

    I must admit that my choice of 30 seconds for the limit is somewhat arbitrary - my scripts could actually get away with 2 seconds instead, but I feel more comfortable with 30 seconds given the actual application - of course you could use whatever value you feel is suitable.

    Hope this helps!

    0 讨论(0)
  • 2020-12-15 04:42

    This is an old thread, but I thought I would post this link, as it helped me quite a bit on this issue. Essentially what it's saying is the server configuration can override the php config. From the article:

    For example mod_fastcgi has an option called "-idle-timeout" which controls the idle time of the script. So if the script does not output anything to the fastcgi handler for that many seconds then fastcgi would terminate it. The setup is somewhat like this:

    Apache <-> mod_fastcgi <-> php processes
    

    The article has other examples and further explanation. Hope this helps somebody else.

    0 讨论(0)
  • 2020-12-15 04:52

    Checkout this, This is from PHP MANUAL, This may help you.

    If you're using PHP_CLI SAPI and getting error "Maximum execution time of N seconds exceeded" where N is an integer value, try to call set_time_limit(0) every M seconds or every iteration. For example:

    <?php
    
    require_once('db.php');
    
    $stmt = $db->query($sql);
    
    while ($row = $stmt->fetchRow()) {
        set_time_limit(0);
        // your code here
    }
    
    ?>
    
    0 讨论(0)
提交回复
热议问题