I only have this issue now. Every time I make a change in my twig I have to cache:clear
. as well as no errors are being shown if something is wrong in the code? What do I do?!
I had faced this problem multiple times. If your website was accessing by so many user and you clear the cache. i am sure your website was down for couple for minutes until the new cache generated.
So clear cache on production server should not be a regular activity. There are couple of solution or tricks to overcome from this problem:
how to clear the cache
php app/console cache:clear
chmod -R 777 app/cache
chmod -R 777 app/logs
Alternative
You have to do some changes in app.php file located in web folder.
change
$kernel = new AppKernel('prod', false);
to
$kernel = new AppKernel('prod', true);
and clear the cache
I just created a console command to selectively list or delete twig cache files manually, instead of running a time consuming clear:cache which clears everything. The syntax is:
kmlf:twig --clear --env=dev AcmeBundle::nglayout.html.twig AcmeBundle:Simple:simple3.html.twig
you can eliminate the --clear flag if you just want to list the cache file locations. It seems to work well in both prod and dev environments for Symfony 2.3:
use Symfony\Component\Console\Command\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\Output;
class TwigCacheCommand extends ContainerAwareCommand
{
public function configure()
{
$this->setName('kmlf:twig')
->setDescription('selectively manage the twig cache')
->addArgument(
'names',
InputArgument::IS_ARRAY,
'Example AcmeBundle:Section:view.html.twig',
null
)->addOption('clear','c', InputOption::VALUE_NONE, 'delete cache files' );
}
public function write($output, $text) {
$output->writeln($text);
}
public function execute(InputInterface $input, OutputInterface $output)
{
$environment = $this->getContainer()->get('twig');
$names = $input->getArgument('names');
$actionName = null;
if ($input->getOption('clear')) {
$actionName = 'deleting';
$action = function ($fileName) {
unlink($fileName);
};
} else {
$actionName="path:";
$action = function ($filename) {
};
}
foreach ($names as $name) {
$fileName = $environment->getCacheFilename($name);
if (file_exists($fileName)) {
$action($fileName);
} else {
$fileName = 'not found.';
}
$this->write($output, $actionName.' '.$name."\ncacheFile: ".$fileName);
}
$this->write($output, 'Done');
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With