Joomla Performance: clean JCH's Cache Files with Cron or Manually with PHP
JCH Optimize is a Very Good Plugin for to Optimize and Speed Up Joomla.
In the Basic Options, You have Three Modes of use for Combined files delivery:
By default the combined files will be loaded as static css and javascript files. You would need to include directives in your .htaccess file to gzip these files. You can use PHP files instead that will be gzipped if that option is set. PHP files can be loaded with a query attached with the information to find the combined files, or you can use url rewrite if it's available on the server so the files can be masked as static files. If your server prohibits the use of the Options +FollowSymLinks directive in .htaccess files use the respective option.
Static CSS and Javascript Files [Standard Mode]
In this mode, JCH will create Two Folders:
cache > plg_jch_optimize
media > plg_jchoptimize > cache
Now if You have a Limited Disk Space on your Hosting, can be a problem because those folders can contain thousands of files if Your Website is Medium / Big.
With Standard JCH Clean, You can erase ALL Files but it's my Opinion that it would be a waste of resources because the plugin must Restart ALL Work.
Delete Files older than X Days with Cron
I modded, expanded and adapted this PHP Script .
You have to create in the root of Your WebSite a PHP file called cleanJCH.php (for Example) and You paste in it this:
<?php
$days = 3;
$dir = '/home/YOUR_FOLDER/public_html/cache/plg_jch_optimize';
if ($handle = opendir($dir)) {
while (( $file = readdir($handle)) !== false ) {
if ( $file == '.' || $file == '..' || is_dir($dir.'/'.$file) ) {
continue;
}
if ((time() - filemtime($dir.'/'.$file)) > ($days *86400)) {
unlink($dir.'/'.$file);
}
}
closedir($handle);
}
$daysJCH = 3;
$dirJCH = '/home/YOUR_FOLDER/public_html/media/plg_jchoptimize/cache';
if ($handleJCH = opendir($dirJCH)) {
while (( $fileJCH = readdir($handleJCH)) !== false ) {
if ( $fileJCH == '.' || $fileJCH == '..' || is_dir($dirJCH.'/'.$fileJCH) ) {
continue;
}
if ((time() - filemtime($dirJCH.'/'.$fileJCH)) > ($daysJCH *86400)) {
unlink($dirJCH.'/'.$fileJCH);
}
}
closedir($handleJCH);
}
?>
I used Absolute Path for $dir and $dirJCH but You can use Relative Path if You Want.
Now You must to go on Your Hosting Control Panel and You create a Cron Process.
I have configured it to work every day at 3am:
0 3 * * * curl --silent –compressed 'http://www.YOUR_WEBSITE.COM/cleanJCH.php'
Delete Files older than X Days Manually
<?php
$days = 3;
$dir = '/home/YOUR_FOLDER/public_html/cache/plg_jch_optimize';
$nofiles = 0;
if ($handle = opendir($dir)) {
while (( $file = readdir($handle)) !== false ) {
if ( $file == '.' || $file == '..' || is_dir($dir.'/'.$file) ) {
continue;
}
if ((time() - filemtime($dir.'/'.$file)) > ($days *86400)) {
$nofiles++;
unlink($dir.'/'.$file);
}
}
closedir($handle);
echo "Total files deleted in Joomla Cache Folder: $nofiles \n";
}
$daysJCH = 3;
$dirJCH = '/home/YOUR_FOLDER/public_html/media/plg_jchoptimize/cache';
$nofilesJCH = 0;
if ($handleJCH = opendir($dirJCH)) {
while (( $fileJCH = readdir($handleJCH)) !== false ) {
if ( $fileJCH == '.' || $fileJCH == '..' || is_dir($dirJCH.'/'.$fileJCH) ) {
continue;
}
if ((time() - filemtime($dirJCH.'/'.$fileJCH)) > ($daysJCH *86400)) {
$nofilesJCH++;
unlink($dirJCH.'/'.$fileJCH);
}
}
closedir($handleJCH);
echo "Total files deleted in JCH Cache Folder: $nofilesJCH \n";
}
?>
http://www.YOUR_WEBSITE.COM/cleanJCH.php
Conclusion
With this PHP Script, You erase ONLY the files older than 3 days.
Of Course, You can change this value in 7 Days (example) if You Want.
You must to change this Value Strings: $days and $daysJCH.
I suggest using Equal Value for a more correct work of JCH Optimize.
Sono Il Re sul Carro Danzante. Attraversando La Città Getto Via I Coriandoli Della Vostra Tristezza Regalando Passione Ed Estasi Nei Vostri Occhi.
Follow Trony on: FusoElektronique | Facebook | Twitter | Soundcloud
Please Log in or Create an account to join the conversation.
You might also be interested...
- You are here:
- Home ↬
- Forum ↬
- Design's Factory ↬
- Computers - WebMastering - Consolle ↬
- Joomla Performance: clean JCH's Cache Files with Cron or Manually with PHP
Community and Web Radio of Electronic Music since July 2008. Rome, Italy
Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0) 2021.
About us | Our team | Cookie Policy | Privacy Policy | Terms and Conditions | Contact us | Sitemap