Fatal error: Maximum execution time of 30 seconds exceeded in PHP

The error stated in the title occurs if a database query / script is taking more than 30 seconds to execute. It is a safe guard mechanism in case you mistakenly ended up running an infinite loop.
However, many times it can be a genuine script taking m,ore time due to certain external factors.
In my case it was because of the database query with number of joins taking extra time.

The issue can be handled in 2 ways i.e.

  1. If you feel that it is just a single one off case taking more time then write the following line just before executing the script. It will increase the script execution time to 5 minute (300 seconds)

    ini_set('max_execution_time', 300); //300 seconds = 5 minutes

  2. But if you want to increase the execution time for the entire application then you will have to edit the PHP.INI file. You will have to update the below setting i.e.

    Find this line:
    max_execution_time

    Change its value to 300:
    max_execution_time = 300

0 comments:

Post a Comment