2

My server has gone down twice in the last 3 weeks because of an excessive number of files being created in the compiled_templates folder. This causes all of the inodes on our server to be used up causing the site to crash.

We previously thought this may have been because of a security test that hit multiple URLs on the site and generated too many templates. The original question can be seen here Security test generated large compiled_templates directory, site outage

This time there was no unusual traffic spike, so I can't assume it was because of the security testing. The only common thread seems to be that garbage collection is either not deleting the old compiled templates or craft is mis-configured. Any insights into this issue would be much appreciated.

EDIT: Looking in the compiled_templates folder it seems there are a few hundred different folders with names like 00 a9 b3 ... and inside those folders are sometimes hundreds of PHP files. I can't track down what templates some of them go to. For example one of the comments up to reads: /* __string_template__cc8a06d92434271d04fe341ad237b568da4c65f004cfec4d1fc576ee4e9b6c4a */

They have functions that echo out single lines of text, these functions are called doDisplay. I am not the original author of this site and am not an expert at Craft. I appreciate the help.

  • Yeah, I've just discovered a Craft site that has a /craft/runtime/compiled_templates folder that is 1.3GB! Still investigating. – Simon East Feb 13 '18 at 0:14
1

How many files are in the compiled_templates directory? There should be a 1:1 correlation between the number of actual templates you have, and the number of cached .php compiled templates in the compiled_templatesfolder.

It shouldn't have anything to do with 404 errors, etc.

I've never seen nor heard of the situation that you've described.

  • 1
    Additionally at the top of every compiled template is a comment with the source template that it was compiled from. Might help in tracking down where they are coming from. – Brad Bell Jul 18 '17 at 3:01
  • There are probably over a hundred folders with various names like '00' 'a9' 'a8' and inside those folders there are a hundred other php files with names like 00f1fbe8f11466faed7ba834b345155794841b35579c9839f1a01a1d5242d164.php – gautsch Jul 18 '17 at 13:27
  • Can you peek at the files as per Brad's suggestion, to see where they are all coming from? Something definitely doesn't sound right here. – andrew.welch Jul 18 '17 at 16:13
  • @khalwat I updated the main question above but they are all coming from string templates of some sort. The comments at the top of the files read like this: "/* __string_template__cc8a06d92434271d04fe341ad237b568da4c65f004cfec4d1fc576ee4e9b6c4a */" – gautsch Jul 18 '17 at 17:20
  • Brad, khalwat, thank you for the context so far. I wanted to give some additional background on what we're seeing when these string templates generate: we recently upgraded from Craft 2.3 to 2.6, and had a few macro templates with template_from_string invocations that looked like: include(template_from_string(page.name)|raw|e) -- these would throw an error after the upgrade, and we had to remove the |raw|e filters to avoid "Unable to find the template __string_template__8c58...." errors. – TJ Nicolaides Jul 24 '17 at 18:46
1

If the compiled template class names start with __string_template, then that means the source template doesn't live in the craft/templates folder, but it was rendered at runtime by calling Twig's Environment->createTemplate().

Craft does this for rendering Twig strings to a template for things like a Section's Entry URL Format settings, which can be any valid Twig code.

Plugins can also do this as well. Do you happen to have the Preparse plugin installed? Seems like a potential candidate if so.

A bit of a hacky workaround, but you could always setup a cron-job to delete the contents of that folder either full-on or based on some other logic (how old they are, number of files, etc.). They'll get re-generated as needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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