DEVELOPMENT by Pedro Resende

Cache Clear Method

How to call Symfony's cache:clear command ?

Post by Pedro Resende on the 20 of May of 2015 at 02:55

This week, while working on a project, I've decided to implemente a cache clear function.

After investigating a while, I've found out the easiest way was by calling Symfony command

$ php app/console cache:clear

However, using something like

exec("php app/console cache:clear"); 

doesn't seems the best option.

It was when I've found something like


use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Bundle\FrameworkBundle\Console\Application;

class Something {

    private function cacheClear() {
        $input = Argvinput(array('console','cache:clear'));
        $application = new Application($this->get('kernel'));

You can see it's a pretty simple method that does the expected job in a clean way ;)