dunglas / frankenphp

🧟 The modern PHP app server
https://frankenphp.dev
MIT License
6.64k stars 218 forks source link

Cache (Twig) is not regenerated in dev mode #55

Closed COil closed 1 year ago

COil commented 1 year ago

Hi, I use the FrankenPHP demo with the worker mode. If we modify a Twig template (with the dev env), docker has to be restarted, so the changes are taken in account. Is it a limitation of the worker mode?

And even if we clear the cache manually, we still have to restart FrankenPHP so see the new changes.

dunglas commented 1 year ago

Yes it's intended. Once the file is loaded in memory by PHP (in this case the PHP file corresponding to the Twig template), it will never be parsed and executed again: it stays in memory.

A solution to use the worker mode in dev would be to add a watcher option that will restart the worker if one of the watched files change. To do so, we could use fsnotify: https://github.com/fsnotify/fsnotify

withinboredom commented 1 year ago

As a workaround @COil, you could try doing something like this in dev mode: https://github.com/dunglas/frankenphp/issues/37#issue-1413245382

COil commented 1 year ago

The problem is that even FrankenPHP is restarted, the Symfony cache still has to be regenerated. That's what I tried to fix with https://github.com/strangebuzz/cache-watcher. I have to modify it to use https://github.com/fsnotify/fsnotify BTW. Ideally, both should be done.

withinboredom commented 1 year ago

IIRC, Twig allows you to disable caches too? I can't remember if Symphony exposes this option easily, as it is quite a bit lower level and usually not desired, but that may possibly be a simpler solution in this case.

COil commented 1 year ago

I took Twig as an example, but it must be the same with the different cache types. Env vars, yaml, translation, entities... Check out https://github.com/strangebuzz/cache-watcher/blob/b5b16d039f7cc59e79ccbad949f2c72a4465e92c/symfony/files.go#L49 (Symfony)

withinboredom commented 1 year ago

👍, I think what @dunglas suggested would be the simplest long-term solution; I was just trying to help you discover a workaround without a bunch of code churn.

COil commented 1 year ago

Closing this for now as it's an expected behaviour.