Maximum execution time taken by a PHP Script Last Updated : 25 Jan, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report One important aspect of PHP programs is that the maximum time taken to execute a script is 30 seconds. The time limit varies depending on the hosting companies but the maximum execution time is between 30 to 60 seconds. The user may get errors of maximum time limit exceeds due to some heavy import or export of files or program which involves sending mail to many recipients. To avoid the situation, you need to increase the execution time limit.This article describes how to change or control the maximum execution time of a PHP script.Prerequisite required: You have already a custom php.ini file set up in your application or a request has to be done to the owner who maintains it. If some of the PHP scripts take longer time then the server stops and throws an error: Fatal error: Maximum execution time of..seconds exceeded in this_file.php on line... To avoid this situation, you can change the max_execution_time directive in php.ini configuration file. Let us look at the ways by which we can set time for script execution in PHP. These are listed below: Search for max_execution_time directive in the php.ini file and edit the value of it, 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 = 4000The default value of the directive is changed as required. Note: We have to restart the web-server, once the changes are done in the configuration file. By this setting, the configuration is made global to all PHP scripts. Changes done to this file in an incorrect way can create problems to the web-server or live projects.Use PHP inbuilt function set_time_limit(seconds) where seconds is the argument passed which is the time limit in seconds. It is used, when the user changes the setting outside the php.ini file. The function is called within your own PHP code. Use set_time_limit(0) when the safe mode is off.Note: If the function is called at the very start of the program, then the value passed to the function will be the time limit for the execution of the script. Otherwise, if the function is called in the middle of the code, then the partial script is executed and then for the rest of the script, the time limit is applied.Use PHP inbuilt function ini_set(option, value) where the parameters are the given configuration option and the value to be set. php // The program is executed for 3mns. <?php ini_set('max_execution_time', 180); ?> It is used when you need to override the configuration value at run-time. This function is called from your own PHP code and will only affect the script which calls this function. Use init_set('max_execution_time'0) when you want to set unlimited execution time for the script.Note: Use init_set() function when the safe mode is off. php <?php // Sets to unlimited period of time ini_set('max_execution_time', 0); ?> Note: This function with '0' as a parameter is not a good programming practice but can be used for developing and testing purpose. Before the code is moved to live or production mode, make sure the settings are revoked.For allowing to run the script forever and ignore user aborts, set PHP inbuilt function ignore_user_abort(true). By default, it set to False which throws fatal error when client aborts to stop the script. php <?php ignore_user_abort(); ?> Use php_value command to change the settings in Apache configuration files and .htaccess files. Syntax: php_value name valueThis sets the value for that particular directive as specified. php_value max_execution_time 200Use of cPanel configuration setting options for changing the execution time of a script. This can be done in cPanel's dashboard and can be used for setting the time limit for PHP script. Comment More infoAdvertise with us Next Article Maximum execution time taken by a PHP Script G geetanjali16 Follow Improve Article Tags : Web Technologies PHP PHP Programs Similar Reads JavaScript Tutorial JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav 11 min read Web Development Web development is the process of creating, building, and maintaining websites and web applications. It involves everything from web design to programming and database management. Web development is generally divided into three core areas: Frontend Development, Backend Development, and Full Stack De 5 min read React Interview Questions and Answers React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications 15+ min read React Tutorial React is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version 7 min read JavaScript Interview Questions and Answers JavaScript is the most used programming language for developing websites, web servers, mobile applications, and many other platforms. In Both Front-end and Back-end Interviews, JavaScript was asked, and its difficulty depends upon the on your profile and company. Here, we compiled 70+ JS Interview q 15+ min read Domain Name System (DNS) DNS is a hierarchical and distributed naming system that translates domain names into IP addresses. When you type a domain name like www.geeksforgeeks.org into your browser, DNS ensures that the request reaches the correct server by resolving the domain to its corresponding IP address.Without DNS, w 8 min read HTML Interview Questions and Answers HTML (HyperText Markup Language) is the foundational language for creating web pages and web applications. Whether you're a fresher or an experienced professional, preparing for an HTML interview requires a solid understanding of both basic and advanced concepts. Below is a curated list of 50+ HTML 14 min read NodeJS Interview Questions and Answers NodeJS is one of the most popular runtime environments, known for its efficiency, scalability, and ability to handle asynchronous operations. It is built on Chromeâs V8 JavaScript engine for executing JavaScript code outside of a browser. It is extensively used by top companies such as LinkedIn, Net 15+ min read Top 10 Projects For Beginners To Practice HTML and CSS Skills Learning to code is an exciting journey, especially when stepping into the world of programming with HTML and CSSâthe foundation of every website you see today. For most beginners, these two building blocks are the perfect starting point to explore the creative side of web development, designing vis 8 min read Web Development Technologies Web development refers to building, creating, and maintaining websites. It includes aspects such as web design, web publishing, web programming, and database management. It is the creation of an application that works over the internet, i.e., websites.To better understand the foundation of web devel 7 min read Like