PHP clear cache directory
Written by Codes Tips on April 18, 2009 – 12:09 pm -We talked before how we can cache with php. In this post I will show you how we can clear cache. So, for caching a website in php we said we need a directory were we will store all the pages that are showing to the user and save the output to a folder on our server. So in order to clear the cache you should delete all the files from directory that were created.
To do that we only need to loop through the cache folder(go here for learning how to get all the files from a folder) and delete all the files that are inside that folder. Remember to change permissions 777 to cache directory. Here is the code to do that
<? $cachedir = "../cache/"; if ($cachehandle = opendir($cachedir)) { while (false !== ($file = readdir($cachehandle))) { if ($file != "." && $file != "..") { $file2del = $cachedir."/".$file; unlink($file2del); } } closedir($cachehandle); } echo 'Cached cleared.'; ?>
Tags: PHP
Posted in PHP/MYSQL |
One Comment to “PHP clear cache directory”
Leave a Comment
You must be logged in to post a comment.



















May 23rd, 2009 at 3:40 pm
Another way to quickly clean out a folder of files: