How to Fix “Fatal error: Maximum execution time of 30 seconds exceeded” in PHP

When you run a PHP script and encounter an error message  Fatal error: Maximum execution time of 30 seconds exceeded in ..... kalian tidak perlu khawatir. don’t worry. This error message appears because the PHP script that we run has exceeded the time limit (in executing a PHP script) which is set by default by PHP, which is 30 seconds. For that we only need to increase the time limit so that the script can still run and the error message doesn’t appear again. Here are some ways how to fix fatal error: Maximum execution time of 30 seconds exceeded :

1. Overcoming in PHP-FPM

If you are using php-fpm to run your php on the server, you can simply edit the php.ini and increase the value in the max_execution_time variable as much as needed (in seconds), like this :

  • Search for the php.ini file using the find command

find / -name 'php.ini

  • Enter the php.ini file with your favorite editor, for example :

vim /etc/php/7.3/fpm/php.ini 

  • Increase the value in the max_execution_time variable as needed, for example :

max_execution_time = 300

  • Restart the php-fpm service

systemctl restart php-fpm

With this, the error message will not appear while every php file execution that is done does not exceed the time limit that we have set in the max_execution_time. variable. Next, what if we want to customize the execution timeout in each of our php projects ?. This can be done if each of our php project folders has an .htaccess file. we can set it in this file.

 

2. Overcome by editing the .htaccess file

Because the .htaccess file is a directory level configuration file, so if we want to customize the execution time limit for each of our php projects, we can set it here. It’s easy, you just have to enter the file, then add this code (can be placed at the bottom) :

php_value max_execution_time 100

Yep, those are some ways how to fix fatal error: Maximum execution time of 30 seconds exceeded which I can share, I hope this information is useful. Thank you: D

Also Read :
Lukems:

This website uses cookies.