Advertisement

Jan 29, 2021 2 mins

Solve Maximum execution time of 60 seconds exceeded error in PHP

Maximum execution time of 60 seconds exceeded Maximum execution time of 60 seconds exceeded

Ran into trouble adding over 500 records, yeah? Your PHP server is throwing an error. Here’s a quick fix: your server needs a tweak. Some settings are too low, limiting what you can do. Dive into the server’s config (that's like its rulebook) and fix those limits. Not sure how?

Error

Maximum execution time of 60 seconds exceeded

Why is This Error?

The “Maximum execution time of 60 seconds exceeded” error in PHP occurs when a script takes longer to execute than the maximum allowed time limit set by the max_execution_time directive in the PHP configuration. By default, this time limit is often set to 30 or 60 seconds to prevent excessively long-running scripts from causing performance issues on a server.

Here’s a breakdown of the key components of the error

Maximum execution time: Refers to the maximum duration allowed for a PHP script to run, specified by the max_execution_time directive in the PHP configuration.

60 seconds exceeded: Indicates that the script execution has surpassed the specified time limit of 60 seconds.

To address this error, consider the following steps

Optimize Code

Examine the PHP code to identify sections that may be causing the script to run for an extended period. Optimize and streamline the code, avoiding unnecessary loops or operations that might be time-consuming.

Use Proper Indexing

If the script involves database queries, ensure that the database tables are properly indexed. Proper indexing can significantly improve query performance.

Increase Time Limit

If you have control over the PHP configuration, you can increase the max_execution_time value to allow scripts to run for a longer duration. However, this is a temporary solution and may not be suitable for all scenarios.

Example (setting it to 120 seconds):

ini_set('max_execution_time', 120);

Break Tasks into Smaller Steps

If your script is performing a series of tasks, consider breaking them into smaller steps. This way, each step can be completed within the allowed time limit.

Implement Time Checks

Introduce periodic time checks within your script to monitor the elapsed time. If the script is taking too long, you can gracefully exit or handle the situation accordingly.

Use Background Processing

For long-running tasks that don’t need to be completed synchronously, consider offloading them to a background process or a queue system.

It’s important to note that changing the max_execution_time value should be approached with caution, especially on shared hosting environments, as it may have implications on server performance. Ideally, the code should be optimized to run within reasonable time limits.


Comments


  • Avatar

    Danielle Carline

    Posted on

    You can fix this issue by updating php.ini file with a proper time out value.

    Step 1: Open php.ini file in your code editor (If you are using XAMP, the php.ini file usually locates in the C:/xamp/php directory).

    Step 2: Search for max_input_time

    Step 3: Give a proper value. Ex

    max_input_time=120
    

    Step 4: Save changes

    Step 5: Restart your Apache server

    Step 6: (Optional) If you are using any PHP framework, restart it

Write a comment

You can use the Markdown syntax to format your comment.

  • Tags:
  • php
  • Share: