3

When auto_reload option is true, it means when a template file is modified, Twig recompiles the file and then render the content.

Question : Is auto_reload option set to true recommended in production environment?

In my opinion, it should be set to true in production because If i am using GIT and one of my twig template file has new changes, and then i update my production codes using 'git pull', i dont have to clear cache anymore, Twig automatically detects that this template file has been changed and need to recompile it. So when the template file is being rendered, it will be rendered with the most recent changes.

Would anyone agree with me? If not, then what would you recommend?

Bogs Imba
  • 59
  • 5

2 Answers2

2

I don't agree with you :) auto_reload should be set to false in production. Moreover, I don't recommend to do a git pull to do a live update of the production code.

I recommend you to set a deployment mechanism which is safer for your code. This can be as easy as a script console or based on tools such as Capistrano or Deployer.

Javier Eguiluz
  • 3,987
  • 2
  • 23
  • 44
  • Can you specify your reason why... I told my reasons why it should be set to true. Can you contradict it. Thx – Bogs Imba Apr 21 '16 at 04:11
  • Yes. The reason is that doing a "git pull" as a method of deployment of new versions is extremely risky. That's why a recommend you to use a professional tool to do that. Then, when you deploy the applications "the right way", you won't find necessary to deal with this option. The code (and the templates) in production should never change. If a change is needed, just deploy a new version (but use a tool to deploy!). – Javier Eguiluz Apr 21 '16 at 10:46
  • Ok i understand your point. But others said using git is a good practice : http://security.stackexchange.com/questions/45452/is-using-git-for-deploying-a-bad-practice. I googled it and people says nothing wrong using git in production. So my question is still not answered. Hope someone can answer my question clearly. – Bogs Imba Apr 22 '16 at 01:42
1

I know this is an old question, but in case someone stumbles onto it, perhaps a more expanded answer would be useful.
Technically, there is nothing stopping you from using auto_reload = true on production, but one thing: performance. The fact of the matter is that whether you like it or not using any template engine (except PHP itself, since it was designed as such) will incur performance penalty. It may seem minor, yes, but if you are serving thousands of requests per second - they all add up.
When you also add validation and thus recompilation of the cache files (which are actually PHP code), you will get further performance degradation. Again, it's minor by itself, but it can quickly add up. So, Javier is correct saying, that you should use false on PROD, but his reasoning is wrong.
Or maybe just "not entirely correct". GIT is totally OK for deployment, but only if you keep in mind, that it's not really a deployment tool, but rather a version control system (VCS). In a simplified case you will, at least, have different configuration files, for example, with details for database connectivity. Well, you should have different ones for security reasons. And that configuration files should not go to VCS, thus they will be excluded from your deployment, if you are relying only on GIT.
This is a very simple case, but you can much more complex ones, like stuff requiring compilation (TypeScript, SASS/LESS, JS/CSS minification would probably be the simplest ones of those) or just database updates, that you simply can't serve through GIT. And if you do have anything like that - you need to consider something different than GIT.
Oh and, you can also just GIT the cache files resulting from your development, but that would require you to keep generate appropriate pages in Test environment first, so that they are updated.

Simbiat
  • 339
  • 2
  • 12