3

We're running a long, involved template/script (to store the results in a manual cache, of course) and we get:

Fatal error: Maximum execution time of 90 seconds exceeded in system/expressionengine/libraries/Template.php on line 1112

The thing is, I have ini_set("max_execution_time", "3000"); in the script we're running, and nowhere else in EE can I find max_execution_time set to anything else, so... why/where is it being set to 90 seconds?

1 Answer 1

4

system/expressionengine/libraries/Core.php around line 64 (as of v2.9.0):

// Set a liberal script execution time limit, making it shorter for front-end requests than CI's default
if (function_exists("set_time_limit") == TRUE AND @ini_get("safe_mode") == 0)
{
    @set_time_limit((REQ == 'CP') ? 300 : 90);
}

If you have a page that is taking more than 90 seconds to render, I would post a separate question about optimizing that template. ;)

Edit: set_time_limit() resets the counter from zero every time that it's called, so assuming you don't collide with Apache's timeout, you can add that to your script that is getting info about the files on the external server. Perhaps try to limit it to as small as possible; if the files are examined in a loop, place a reasonable timeout extension within the loop prior to each external call, e.g.:

set_time_limit(10);

Or whatever is actually needed for the communication to not be impeded between the two servers.

4
  • Thanks! I forgot about set_time_limit being an analog to the ini_set method. At least that solves the mystery. :) As for this template, it's a script that generates the RSS feed for our podcasts, which involves going out and fetching details about each MP3 file from an external server. It's a time-consuming process. Other than modifying Core.php (and making a global impact) is there an in-template/in-script way of altering this for this one script/template? Commented Aug 6, 2014 at 12:34
  • Surely, I've updated the answer above. Commented Aug 7, 2014 at 13:50
  • So... I tried adding all kinds of counter resets and... still the same issue. And then it hit me: parse order. I had PHP set to parse on output. :) There goes three half-days of my life I'll never get back. Setting it to parse on input obviously was the answer: it makes it actually run the PHP before the script, resetting the time limit. Commented Aug 8, 2014 at 19:46
  • If your script is encapsulated in a plugin, you can avoid needing PHP in your templates at all, incidentally. The plugin could include this external script and trigger it, so the plugin itself would be very simple and you wouldn't likely have to modify the external script. Commented Aug 8, 2014 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.