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

<p>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.</p>

<p>Plugins can also do this as well.  Do you happen to have the <a href="https://github.com/aelvan/Preparse-Field-Craft" rel="nofollow noreferrer">Preparse</a> plugin installed?  Seems like a potential candidate if so.</p>

<p>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.</p>

CC BY-SA 3.0
2017-07-18T18:57:15.340Z
2017-07-18T18:57:15.340Z
Brad Bell
<p>How many files are in the <code>compiled_templates</code> directory? There should be a 1:1 correlation between the number of actual templates you have, and the number of cached <code>.php</code> compiled templates in the <code>compiled_templates</code>folder.</p>

<p>It shouldn't have anything to do with 404 errors, etc.</p>

<p>I've never seen nor heard of the situation that you've described.</p>

CC BY-SA 3.0
2017-07-18T03:01:10.867Z
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
CC BY-SA 3.0
2017-07-18T13:27:09.280Z
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
CC BY-SA 3.0
2017-07-18T16:13:49.887Z
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
CC BY-SA 3.0
2017-07-18T17:20:39.450Z
@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
CC BY-SA 3.0
2017-07-24T18:46:36.930Z
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
CC BY-SA 3.0
2017-07-24T18:56:23.143Z
After that change, we are seeing unique templates generated for each page refresh - for example, where we would expect one file containing "A very special string" template after 6 page refreshes, instead we see 6: https://pastebin.com/Ecq36Myv
TJ Nicolaides
CC BY-SA 3.0
2017-07-24T18:58:32.933Z
Something that led us to believe that these Twig templates were being treated differently in this version was this answer: https://craftcms.stackexchange.com/a/16268/6917 - not sure if this is applicable. FWIW, also not the author or a Craft expert.
TJ Nicolaides
CC BY-SA 3.0
2017-07-18T01:51:57.763Z
2017-07-18T01:51:57.763Z
andrew.welch
<p>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.</p>

<p>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 <a href="https://craftcms.stackexchange.com/questions/20985/security-test-generated-large-compiled-templates-directory-site-outage">Security test generated large compiled_templates directory, site outage</a></p>

<p>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.</p>

<p>EDIT: Looking in the <code>compiled_templates</code> 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: <code>/* __string_template__cc8a06d92434271d04fe341ad237b568da4c65f004cfec4d1fc576ee4e9b6c4a */</code></p>

<p>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.</p>

CC BY-SA 3.0
2018-02-13T00:14:08.110Z
Yeah, I've just discovered a Craft site that has a `/craft/runtime/compiled_templates` folder that is 1.3GB! Still investigating.
Simon East
<database><config><php><server>
compiled_templates folder using up inodes on Ubuntu 14.04 Server
# compiled_templates folder using up inodes on Ubuntu 14.04 Server

(Asked by: username_0 on 2017-07-18)

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](https://craftcms.stackexchange.com/questions/20985/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.

**Tags:** database, config, php, server
> **Comments:**
> **username_1**: Yeah, I've just discovered a Craft site that has a `/craft/runtime/compiled_templates` folder that is 1.3GB! Still investigating.  

---

## 2 answers

### Answer by username_2 on 2017-07-18. Score: 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](https://github.com/aelvan/Preparse-Field-Craft) 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.


---

### Answer by username_3 on 2017-07-18. Score: 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_templates`folder.

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

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

> **Comments:**
> **username_2**: 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.  
> **username_0**: 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  
> **username_3**: 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.  
> **username_0**: @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 */"  
> **username_4**: 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.  
> **username_4**: After that change, we are seeing unique templates generated for each page refresh - for example, where we would expect one file containing "A very special string" template after 6 page refreshes, instead we see 6: https://pastebin.com/Ecq36Myv  
> **username_4**: Something that led us to believe that these Twig templates were being treated differently in this version was this answer: https://craftcms.stackexchange.com/a/16268/6917 - not sure if this is applicable. FWIW, also not the author or a Craft expert.  

---

