Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Remove compiled files

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
bimal
Smarty Elite


Joined: 19 Apr 2007
Posts: 423

PostPosted: Wed Feb 18, 2009 4:24 pm    Post subject: Remove compiled files Reply with quote

Some servers do not allow to remove the files created by php/apache or www or httpd like users, if in Linux machines.
In your smarty compiles, smarty will make the files. So, you may be unable to remove them using FTP, because of restrictions in file permissions.
In this case, if you still need to remove the compiled files, you should ask a php script do it for you.
(In linux, the user who creates files may have high control, and thus can remove them too).

Use the following code in a different file, configure it to say, where is the location of your compiles directory is, and then run it.
If will try to emtpy anything inside this directory.

In a good environment, it does not matter anything significant to remove all your compiled file. However, removing the compiles files can be important for a developer.

WARNING: Use the script responsibly. It is dangerous, unless you know what you are going to do.

Code:
<?php
/**
* File: remove_compiles.php
* Used to remove the compliled files of smarty.
* WARNING: IF YOU DO NOT SET YOUR SMARTY COMPILES DIRECTROY CORRECTLY,
* THEN YOU MAY LOSE YOUR SCRIPTS.
* I AM NOT RESPONSIBLE FOR THE LOSS, IF YOU CAN NOT USE IT CORRECTLY.
*
* @author Bimal Poudel <smarty @ bimal.org.np>
*/

function cleanup_compiled_files()
{
   $dir = './application/templates_c'; # Set it correctly.
   if($handle = opendir($dir))
   {
      while (false !== ($file = readdir($handle)))
      {
         if(!in_array($file, array('.', '..')))
         {
            $f = "{$dir}/{$file}";
            echo("<br>{$f}");
            unlink($f);
         }
      }
      closedir($handle);
   }
}

cleanup_compiled_files();
?>
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Feb 18, 2009 4:40 pm    Post subject: Reply with quote

Or, just do it the easy way:

Code:
$smarty->clear_compiled_tpl();


http://www.smarty.net/manual/en/api.clear.compiled.tpl.php
Back to top
View user's profile Send private message Visit poster's website
bimal
Smarty Elite


Joined: 19 Apr 2007
Posts: 423

PostPosted: Wed Feb 18, 2009 5:00 pm    Post subject: Conditional clearance only Reply with quote

Thanks for this API.

But will it try to clear the compiled files everytime a page is browsed? Won't this force to recompile the scripts everytime?

If so, this API would be highly useful to make admin tools.
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Feb 18, 2009 5:18 pm    Post subject: Reply with quote

It clears the directory each time $smarty->clear_compiled_tpl() is called. This is not something you would want to do on every page load.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP