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:
Code:
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:
Code:
<?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:
Code:
0 3 * * * curl --silent –compressed 'http://www.YOUR_WEBSITE.COM/cleanJCH.php'
Delete Files older than X Days Manually
Code:
<?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";
}
?>
It's so similar to Cron Version but for to work You must use the
Browser with a Url like this:
Code:
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.