php - Programmatically clear cache on symfony 2 -


i'm trying empty symfony 2 cache through application if doing php app/console cache:clear.

i've tried many different solutions, such as:

//solution 1 $process = new process('php '.__dir__.'/../../../../../app/console cache:clear'); $process->settimeout(3600); $process->run();  //solution 2 $input = new stringinput(null); $output = new nullconfigurationoutput(); $command = new cacheclearcommand(); $command->setcontainer($container); $command->run($input, $output);  //solution 3     $container->get('cache_clearer')->clear($container->getparameter('kernel.cache_dir')); 

i've tried rm -rf cache folder.

none of them working i'm getting many errors. following error 1 i'm getting on solution 2 (which seemed best):

failed start session: started php ($_session set).

seems symfony trying rebuild page or reboot application during render process.

how clear cache via php code?

edit : i'm trying regenerate cache because of routing system. i've made bundle take symfony 2 route , add possibility rewrite seo purpose (example : have front_category route point /category, bundle can rewrite category-seo-optimized.html).

if i'm on route needs particular parameter, such id, need make special route in order rewrite it. example, /category/3 need create route named category_3 and.. in order let symfony knows i've changed routing system, had clear cache.

exactly same problem had. simplest solution me was:

use symfony\component\filesystem\filesystem; 

and in controller:

$fs = new filesystem(); $fs->remove($this->container->getparameter('kernel.cache_dir')); 

this delete cache directory current environment.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -