Change language

Maximum PHP script execution time

This article describes how to change or control the maximum execution time of a PHP script.Prerequisite:
You already have a custom php. ini configured in your application, or you need to contact the owner who supports it. If some of the PHP scripts take longer, the server stops and throws an error:
Fatal error: Maximum execution time of..seconds exceeded in this_file.php on line ...
To to avoid this situation, you can change the directive in the php.ini config file. Let’s see how we can set the script execution time in PHP. They are listed below:
  • Find the directive in the file and change its value as required by the PHP script.
    ; Maximum execution time of each script, in seconds; http://php.net/max-execution-time; Note: This directive is hardcoded to 0 for the CLI SAPI max_execution_time = 4000
    The directive’s default value changes as needed. 
    Note: we have to restart the web server as soon as the changes will be made to the config file. This parameter makes the configuration global for all PHP scripts. Changes made to this file in the wrong way can create problems for the web server or live projects.
  • Use the built-in PHP function set_time_limit (seconds), where seconds - this is the passed argument, which is the time limit in seconds. It is used when the user changes settings outside of the php.inifile. The function is called from your own PHP code. Use when disabled. Note. If the function is called at the very beginning of the program, then the value passed to the function will be limited by the script execution time. Otherwise, if the function is called in the middle of the code, the partial script is executed and then the time limit is applied to the rest of the script.
  • Use a built-in PHP function where parameters are a given config parameter and value to be set. // The program is executed in 3ms
    ini_set ( ’max_execution_time’ , 180); ?> It is used when you need to override the config value at runtime ... This function is called from your own PHP code and will only affect the script that calls this function. Use if you want to set unlimited script execution time. Note. Use the function when it is disabled.
    // Installed for an unlimited period of time ini_set ( ’max_execution_time’ , 0); ?>
    Note. This function with setting "0" is not good programming practice, but it can be used for development and testing purposes. Make sure to deselect the settings before putting your code into production or production mode.
  • To allow the script to run permanently and ignore user interrupts, install a built-in PHP function. It defaults to False, which throws a fatal error when the client aborts the script.
    ignore_user_abort();
    ?>
  • Use the command to change settings in configuration files and Apache files. 
    Syntax:
    php_value name value
    This sets the value for that particular directive as specified.
    php_value max_execution_time 200 
  • Using cPanel configuration settings to change script execution time. This can be done in your cPanel control panel and can be used to set a time limit for a PHP script.

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method