Fatal error: Maximum execution time of 30 seconds exceeded

后端 未结 16 755
逝去的感伤
逝去的感伤 2020-11-22 01:27

I am downloading a JSON file from an online source and and when it runs through the loop I am getting this error:

Fatal error: Maximum execution time

相关标签:
16条回答
  • 2020-11-22 01:42

    We can solve this problem in 3 different ways.

    1) Using php.ini file

    2) Using .htaccess file

    3) Using Wp-config.php file ( for Wordpress )

    0 讨论(0)
  • 2020-11-22 01:42

    I have same problem in WordPress site, I added in .htaccess file then working fine for me.

    php_value max_execution_time 6000000
    
    0 讨论(0)
  • 2020-11-22 01:43

    Edit php.ini

    Find this line:

    max_execution_time
    

    Change its value to 300:

    max_execution_time = 300
    

    300 means 5 minutes of execution time for the http request.

    0 讨论(0)
  • 2020-11-22 01:44

    You can remove the restriction by seting it to zero by adding this line at the top of your script:

    <?php ini_set('max_execution_time', 0); ?>
    
    0 讨论(0)
  • 2020-11-22 01:44

    To extend your max_execution_time you can use either ini_set or set_time_limit.

    // Set maximum execution time to 10 seconds this way
    ini_set('max_execution_time', 10);
    // or this way
    set_time_limit(10);
    

    !! But be aware that, both functions restarts also counting of time script has already taken to execute

    sleep(2);
    ini_set('max_execution_time', 5);
    
    register_shutdown_function(function(){
        var_dump(microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']);
    });
    
    for(;;);
    
    //
    // var_dump outputs float(7.1981489658356)
    //
    

    so if you want to set exact maximum amount of time script can run, your command must be very first.

    Differences between those two functions are

    • set_time_limit does not return info whether it was successful but it will throw a warning on error.
    • ini_set returns old value on success, or false on failure without any warning/error
    0 讨论(0)
  • 2020-11-22 01:45

    I had the same problem and solved it by changing the value for the param max_execution_time in php.ini, like this:

    max_execution_time = 360      ; Maximum execution time of each script, in seconds (I CHANGED THIS VALUE)
    max_input_time = 120          ; Maximum amount of time each script may spend parsing request data
    ;max_input_nesting_level = 64 ; Maximum input variable nesting level
    memory_limit = 128M           ; Maximum amount of memory a script may consume (128MB by default)
    

    I hope this could help you.

    0 讨论(0)
提交回复
热议问题