Skip to content

Instantly share code, notes, and snippets.

@basdek
Created May 2, 2013 09:25
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save basdek/5501165 to your computer and use it in GitHub Desktop.
Save basdek/5501165 to your computer and use it in GitHub Desktop.
Clear cache from Controller in Symfony2
<?php
// asume controller context here
public function cccAction()
{
$kernel = $this->get('kernel');
$application = new \Symfony\Bundle\FrameworkBundle\Console\Application($kernel);
$application->setAutoExit(false);
$options = array('command' => 'cache:clear',"--env" => 'prod', '--no-warmup' => true);
$application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
return new Response();
}
?>
@aalaap
Copy link

aalaap commented Jan 17, 2017

I'm trying to run this from within a command (not a controller), but it keeps clearing the dev cache, in spite of specifying '--env' => 'prod' in the options array. Symfony 2.8.

@kironet
Copy link

kironet commented Jan 18, 2017

crearing dev

My solutions are:
exec("php bin/console cache:clear --env=prod");
or

$fs = new Filesystem();
$fs->remove($this->getParameter('kernel.cache_dir'));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment