- How to Increase Maximum Execution Time Limit of PHP Scripts
- Increase Maximum Execution Time Limit of PHP Scripts
- Method #1 : Global PHP Configuration
- Method #2 : ini_set()
- Method #3 : set_time_limit()
- Ошибка php Maximum execution time of 30 seconds exceeded
- Решение проблемы с помощью ini_set
- Решение проблемы с помощью php.ini
- Причина возникновения ошибки Maximum execution time exceeded
- How to Solve the ‘Maximum Execution Time of 30 Seconds Exceeded’ Error in PHP
- Understanding the “Maximum Execution Time of 30 Seconds Exceeded” Error
- Resolving the Error by Increasing the Maximum Execution Time
- Permanet Fix Fatal error : Maximum execution time of 30 seconds
- Resolving the Error in Specific Environments
- Resolving the Error by Debugging the PHP Script
- Other examples of quick code fixes for the ‘maximum execution time of 30 seconds exceeded’ error
- Conclusion
- How to Resolve the Fatal error: Maximum Execution time of 30 seconds exceeded in PHP
- Solution A
- Step 1
- Step 2
- Step 3
- Solution B
How to Increase Maximum Execution Time Limit of PHP Scripts
By default, maximum execution time for PHP scripts is set to 30 seconds. If PHP scripts runs longer than 30 seconds, PHP stops the script and report an error. You can change max execution time using the max_execution_time directive in php.ini file.
PHP will exit with the following error once it reaches the maximum allowed time for it to execute your scripts;
Fatal error: Maximum execution time of 30 seconds exceeded in phpcript.php
You can fix this error by increasing the maximum execution time for php. This can be set globally or from within your PHP scripts from these options.
Increase Maximum Execution Time Limit of PHP Scripts
Follow the below methods to increase maximum execution time limit of php script.
Method #1 : Global PHP Configuration
This method will affect all the PHP scripts running in your system. Set the max_execution_time in your PHP configuration file (php.ini) to the number of seconds that want to allow your PHP scripts to execute.
In the below example I have set the maximum execution time for 2 minutes (120 Seconds).
; 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 = 120
Setting it to 0 will impose no time limit whatsoever to the execution of your PHP scripts.
This is not a recommended solution especially in production systems as misbehaved scripts could bring the whole system down.
Restart your web server for the changes to take effect.
Method #2 : ini_set()
This is basically the same as the previous solution, but it’s actually a function that you call from your PHP script. It’s a general function to override any configuration options set in your PHP’s configuration file and will only affect the execution of the scripts that call the function.
When placed at the start of your PHP script, the following function call will allow it to run for 120 seconds (5 minutes).
ini_set('max_execution_time', 120)
Method #3 : set_time_limit()
This is PHP’s built-in function specifically to set the maximum execution time limit of your PHP scripts. It’s to be called from your PHP script as in the previous method and the following example is to also set the limit to 120 seconds (2 minutes).
Ошибка php Maximum execution time of 30 seconds exceeded
Ошибка возникает, когда скрипт выполняется больше определённого в настройках времени. По умолчанию это 30 секунд. Решением проблемы может стать увеличение времени исполнения скриптов php.
Решение проблемы с помощью ini_set
Можно прописать в начале кода PHP конструкцию, которая увеличит время исполнения скрипта до 600 секунд:
ini_set('max_execution_time', 600);
В WordPress её можно определить в файле wp-config.php в корне сайта после определения константы define( ‘WP_DEBUG’, false );
Решение проблемы с помощью php.ini
С помощью phpinfo находим расположение php.ini. Например, он может располагаться тут: /etc/php5/fpm/php.ini
Причина возникновения ошибки Maximum execution time exceeded
Проблема часто заключается в неверно построенной архитектуре кода.
- Импорт одномоментно большого количества данных. Увеличение max_execution_time в данном случае оправданно, однако, позаботьтесь, чтобы NGINX не возвращал 504 ошибку, не дождавшись ответа от бекенда в отведённый срок.
- Проблемой также может послужить зацикленная рекурсия на основе While.
- Либо же долгое исполнение может быть из-за долгого получения данных из базы данных.
- Также, проблемой может служить слишком долгое ожидание ответа от внешнего ресурса, скажем, через file_get_contents
How to Solve the ‘Maximum Execution Time of 30 Seconds Exceeded’ Error in PHP
Learn how to fix the ‘maximum execution time of 30 seconds exceeded’ error in PHP by increasing the maximum execution time, debugging the script, and following best practices. Get helpful tips and techniques to ensure your PHP scripts run smoothly.
- Understanding the “Maximum Execution Time of 30 Seconds Exceeded” Error
- Resolving the Error by Increasing the Maximum Execution Time
- Permanet Fix Fatal error : Maximum execution time of 30 seconds
- Resolving the Error in Specific Environments
- Resolving the Error by Debugging the PHP Script
- Other examples of quick code fixes for the ‘maximum execution time of 30 seconds exceeded’ error
- Conclusion
- How do I fix maximum execution time of 30 seconds exceeded?
- How to solve maximum execution time of 30 seconds exceeded in PHP?
- How do you solve the fatal error maximum execution time of 300 seconds exceeded?
- What is max execution time?
If you are a PHP developer, you may have come across the “maximum execution time of 30 seconds exceeded” error. This error occurs when a PHP script takes longer than 30 seconds to execute, and it can be frustrating to deal with. Fortunately, there are several ways to resolve this error. In this blog post, we will explore the key points, important points, and helpful points related to resolving the “Maximum execution time of 30 seconds exceeded” error in PHP.
Understanding the “Maximum Execution Time of 30 Seconds Exceeded” Error
The “Maximum Execution Time of 30 seconds exceeded” error occurs when a PHP script takes longer than 30 seconds to execute. This default maximum execution time can be changed by editing the max_execution_time value in the php.ini file. The error can also be caused by a plugin or other software and can be fixed by uninstalling it.
Resolving the Error by Increasing the Maximum Execution Time
To resolve the error, the maximum execution time can be increased by editing the php.ini file or using the set_time_limit() function. Increasing the time limit to 300 seconds is often sufficient to solve the problem. It is important to note that increasing the maximum execution time can also increase the memory_limit value in the php.ini file.
Permanet Fix Fatal error : Maximum execution time of 30 seconds
Fix php execution time error on WAMP or XAMPP local web serverincrease php execution time Duration: 0:57
Resolving the Error in Specific Environments
XAMPP and WAMP users can increase the execution time by modifying the config.inc.php file. The error can also occur in PhpMyAdmin and WordPress. The error can be fixed by adding a line in wp-config.php or by changing the max_execution_time PHP directive in MultiPHP INI Editor.
Resolving the Error by Debugging the PHP Script
Debugging the PHP script for any infinite loops may also solve the issue. Using a profiling tool can help identify performance bottlenecks and optimize the code. Best practices for avoiding long-running PHP scripts include using pagination for large data sets and caching frequently accessed data.
Other examples of quick code fixes for the ‘maximum execution time of 30 seconds exceeded’ error
ini_set('max_execution_time', '300'); //300 seconds = 5 minutes
And Change xampp\php\php.ini to max_execution_time = 1000; or higher value
In Php , Fatal error: Maximum execution time of 120 seconds exceeded in code example
//change this in php.ini max_execution_time = 500
// you need to add this line at the bottom of your .htaccess file Before # END WordPress Like this. php_value max_execution_time 1000 # END WordPress
In Sql , for instance, Maximum execution time of 360 seconds exceeded code example
A better solution here is to change the config that controls phpMyAdmin and not the php.ini file.If you change the php.ini file you effect everything in PHP and should you write that infinite loop that we all do from time to time it will take longer to terminate your infinite loop than is sensible.Note: If you are using the 64bit WAMPServer the base folder name will be wamp64 instead of wamp so please amend the below folder names accordingly.So change \wamp\alias\phpmyadmin.conf. By default it will look something like this although your version of phpMyAdmin will probably be different:Alias /phpmyadmin "c:/wamp/apps/phpmyadmin4.1.14/" Options Indexes FollowSymLinks MultiViews AllowOverride all Require local Order Deny,Allow Deny from all Allow from localhost ::1 127.0.0.1 php_admin_value upload_max_filesize 128M php_admin_value post_max_size 128M php_admin_value max_execution_time 360 php_admin_value max_input_time 360 To extend the maximum time limit for importing a database, change the php_admin_value max_execution_time parameter. You may also need to change the other parameters as larger databases tend to come in larger files and take longer to read as well. Example: php_admin_value upload_max_filesize 1024M php_admin_value post_max_size 1024M php_admin_value max_execution_time 1800 php_admin_value max_input_time 1800
Conclusion
Resolving the “maximum execution time of 30 seconds exceeded” error in PHP is important for developers to ensure their scripts run smoothly. By increasing the maximum execution time, debugging the script, and following best practices, developers can prevent this error from occurring. Remember to refer to helpful points like php 8 performance improvements and tips for optimizing php code to further improve your PHP scripts.
How to Resolve the Fatal error: Maximum Execution time of 30 seconds exceeded in PHP
Errors are an inseparable part of any working process.
The development is not an exception, either. But it is essential to find proper resolutions to the errors caused by different factors.
In case you have encountered the fatal error: maximum execution time of 30 seconds exceeded in PHP, it means that the actions to do by the Apache web server to carry out your task took a long time. Hence, it was suspended by the limit provided by PHP ini configuration.
To solve the problem, you can go on with changing the setting of a time limit with the function set time limit. There, you can give the maximum execution time in seconds as a parameter.
Below, we will provide you with two handy solutions to the problem.
Solution A
In the framework of the first solution, you should take several easy steps. Let’s check them out.
Step 1
First of all, you should open the php.ini file.
Step 2
The next step is changing the value of “max_execution_time” to a bigger value.
Step 3
The final step is restarting the server.
Solution B
Now, let’s see an alternative solution. This option is more recommended that the first one.
All you need to do is adding set_time_limit(600) inside the code. The input parameter is the maximum execution time. The meaning of 0 is unlimited.
However, you should be careful, as, in the case of an endless job, you may hang your server. So, we recommend you not to set the value too high.