Snippets

Create an account or login to be able to add, comment and rate snippets.

Navigation

clear the cache without symfony command line interface

Some PHP code to clean the cache very useful when you don't have access to symfony "command line interface" on production server.

file: symfony_cc.php

<?php
function deltree($f)
{
  $sf = realpath($sf);
 
  if (is_dir($f)) {
    foreach(glob($f.'/*') as $sf) {
      if (is_dir($sf) && !is_link($sf)) {
        deltree($sf);
        if (is_writable($sf)) {
          echo 'Delete dir.: '.$sf."\n";
          rmdir($sf);
        }
      } else {
        if (is_writable($sf)) {
          echo 'Delete file: '.$sf."\n";
          unlink($sf);
        }
      }
    }
  } else {
    die('Error: '.$f.' not a directory');
  }
}
 
echo '<pre>';
echo 'Clean symfony cache'."\n";
echo "\n";
deltree('../../cache');
echo '</pre>';
 
by Olivier LOYNET on 2008-03-11, tagged cache  cli 

Comments on this snippet

gravatar icon
#1 Sylvain PAPET on 2008-03-11 at 12:07

Tu réinvente la roue, there is already symfony tools to do it : sfToolkit::clearGlob

it is usefull for backend in order to delete template cache when products, news or any content are updated. Example, to delete all templates cache of frontend app : sfToolkit::clearGlob(sfConfig::get('sf_root_cache_dir').'/frontend//template//all');

see : http://www.symfony-project.org/book/1_0/12-Caching

You need to create an account or log in to post a comment or rate this snippet.