Symfony2 - confused cache clear trying to write to pro_ - symfony

My Symfony installation seems to have gotten confused somewhere (probably during a failed cache clear). It seems to think that the production cache folder should be called pro_ instead of prod.
First, when I tried to run $ php console cache:clear --env=prod I got the error message:
[Symfony\Component\Filesystem\Exception\IOException]
Cannot rename "...cache/pro_" to "...cache/pro_".
I'm running on a windows dev machine (so there are no file system permissions issues).
So, I tried deleting all of the cache/* files/folders manually and trying again. This time the cache:clear went through and produced a single prod folder. That folder has subfolders for annotations, assetic, doctrine, sessions and twig.
But when I open the prod front controller (e.g. http://devsite/ in a browser) it fails with the message:
Fatal error: require() [function.require]:
Failed opening required '...cache/pro_/doctrine/orm/Proxies\__CG__AcmeDemoBundleEntityFoo.php'
(include_path='blah, blah, blah')
in ...\vendor\doctrine\common\lib\Doctrine\Common\Proxy\AbstractProxyFactory.php on line 165
From the looks of this it's trying to access cache files in pro_ instead of prod (again).
Looking in the cache folder I can see that __CG__AcmeDemoBundleEntityFoo.php exists under cache\prod but there is now a pro_ folder with annotations and sessions sub-folders.
What's going on and how do I make Symfony forget about pro_ so it can go back to using prod for everything?
I thought everything to do with the cache was stored under the cache folder... is there something else (somewhere) that's storing some reference to pro_? Or am I looking in the wrong place for the solution to this problem?
Edit: Done some more searching and appProdProjectContainer.php contains 16 references to .../cache/pro_. If I manually search and replace these to .../cache/prod the site works. But the next time I run console cache:clear it resets them back to pro_. Where could this errant behaviour be coming from?
Edit2: OK, I got to the bottom of this and have submitted a PR to the Symfony core to try and fix it. The problem was caused by our cache path containing '\' characters which were then escaped in the cache files and failing to match a search/replace command which was meant to clean them up.

app/console cache:clear --env=prod --no-warmup
composer dump-autoload -o
app/console cache:warmup --env=prod

This was a bug in Symfony's handling of cache paths with back-slashes in them.
The short term workaround is to replace them with forward slashes.
Longer term there is a fix posted as https://github.com/symfony/symfony/pull/9184 which will be brought into the core code soon.

Related

Symfony 3 production environment issues

My pages only change in dev environment i.e. when i run my app with app_dev.php in url or with AppKernel set to dev:
$kernel = new AppKernel('dev', true);
For example i have the following twig template:
http://sandbox.onlinephpfunctions.com/code/af8fc051f00e42729a93b0396f37499589ae6a9d
If i somehow modify it (add a div or another tag), the changes wouldn't appear. In order for changes to display i need to be in dev mode. How can i deal with such a behaviour?
In production mode, the cache of the application has to be cleared, otherwise the changes won't occure.
To clear the cache, you have to type in the console, at the root of the project folder (where the folder bin, config, src... are) :
php bin/console cache:clear
At the first visit of the site, the cache will be reloaded that can be (very) long. To avoid this issue, you can warmup the cache, using this command when clearing it :
php bin/console cache:clear --env=prod
If you have no access to the console on the server, but can navigate to the site folder (the one with bin, config etc...) with FTP in example, you can manually delete the content of the var/cache/ folder

Symfony assetic issue file does not exist

I tried to resolve my problem all this morning but I didn't find the solution anywhere.
I have a Symfony project and I use Assetic for my css and js files.
Till today when I ran php bin/console assetic:dump --env=prod, it worked fine.
But now I have this error :
[Symfony\Component\Config\Exception\FileLocatorFileNotFoundException]
The file "C:\wamp\www\PLIE08\app/config/config_=prod.yml" does not exist.
I don't understand why it adds = in my file.
Moreover, after running this command I realized that a folder called "=prod" is created in var/cache in addition to the dev and prod folder.
I tried to update, install composer, clear the cache, look in config file if something was wrong but I'm still blocked...
Somebody can tell me why it searchs the bad file ?
Thanks
try this command bin/console assetic:dump -e prod to verify duplicated =. Otherwise remove the entire content of the cache/prod folder, doest not clear:cache, remove all manually.

symfony assetic dir. does not exist

I've dumped assets using the folling command:
php app/console assetic:dump
I've got a Runtime exception:
The source file "c:\EasyPHP\data\localweb\projects\symfony\src\LV\IndexBundle/Resources/public/images/" does not exist.
It seems to me strange that:
the / goes to \Resources only, after it is /
the directory images does exist in public
no CSS work. I even tried internal CSS in layout.html.twig. Nothing changes.
OS: Windows 10
Try to remove vendors and re composer install, clear cache directory.
If problem isn't solved after that, please share your config.yml here

Symfony 2 cache stuck after config change (FileLoaderException)

Very strange behavior in Sf2 here. I've try to change my config namespaces while i was refactoring code:
adadgio_rocket:
foo: 'bar'
to something simple
adadgio:
rocket: 'bar'
I have change my bundle DI Configuration nodes to reflect that change :
$rootNode = $treeBuilder->root('adadgio');
$rootNode->children()
->scalarNode('rocket')->end()
->end();
Now i have a FileLoaderLoadException still saying able to load the configuration for adadgio but still finds the adadgio_rocket namespace (error results).
I tried to clear the cache thinking this was the issue, but of course, the symphony cache command issues the same error. And its still finds other config namespaces that were removes (and their declaration in the AppKernel as well).
Basically, everything is stuck now.
Yes, that sort of stuff can happen. Simply delete the app/cache/dev directory and run app/console cache:clear again.
If it still doesn’t work, make 100% sure that there are no remainders in the config or referenced in other bundles. If unsure, check:
grep -ir adadgio app/config/ src/ vendor/
It can be a issue of permission also. Give 777 permission to cache and use following to clear cache without warming up the cache:
app/console cache:clear --env=<your environment> --no-warmup

Clear Symfony2 Http Cache

Is there an easy way for fast removing http cache in symfony2? We've over 30.000 files in cache directory and removing them tooks very long. Is there an better way for doing this? Btw...linking the cache to /dev/null when removing...
The easiest way to clear cash would be to use console command:
app/console cache:clear
If this is production – you need to add environment (using paramentr --env=prod. )
As default all console commands run in the dev environment.
So, for example, this command looks like app/console cache:clear -e=prod.
Would always recommend using the Symfony console:
php app/console cache:clear --env=prod
This should be fastest, as it moves/renames your current cache folder and creates a new one before deleting your old cache, so there should zero downtime.
If you look in Symfony's cache directory /var/cache/ you'll find an http_cache directory.
So you could use PHP's exec() to remove the directory.
$root = $this->get('kernel')->getRootDir();
$path = $root . '/../var/cache/prod/http_cache';
exec('rm -rf ' . $path);

Resources