Why?
Why there’s so many of them? Because most of the directories on my hosting has a PHP script inside it.
How?
The first thing I’ve done is by deleting it manually, but it will waste your time. So I created a script to do that automatically, the script also collect the size of total error_log detected.
When?
I set the script to run once every day, you can do that by utilizing “cron job†in the cPanel (see documentation)
Here’s a sample of simple PHP cron Job:
/usr/local/bin/php -f /home/(username)/public_html/(scriptname).php
Who?
Just copy my script in your root directory, then run it on your browser, or run it automatically thru Cron Job.
Demo
See the demo here: http://otakbali.com/hapuserror.php
The Script
Copy and paste the script bellow to a PHP script. Or download it here.
<?php
// set the time limit first, remember, if you have
// a huge number of files, it will be useful
set_time_limit(36000);
$dir = "./";
$num=0;
$bytes=0;
$deleted=0;
$bytesdel=0;
$echo="";
echo "Looking for <b>error_log</b> in every directories <br/>";
buka($dir);
$bytes=format_bytes($bytes);
$bytesdel=format_bytes($bytesdel);
echo "Found $num error_log files ($bytes),
and deleted $deleted ($bytesdel) files.";
echo "<hr/> <ol>$echo</ol>";
// below are the functions, modify it on your risk
// open directory, search error_log, delete it
function buka($dir){
global $num, $deleted, $bytes, $bytesdel, $echo;
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if(($file!=".") and ($file!="..")){
// cek sub dir,
if($dir=="./"){
$cek=$file;
} else {
$cek="$dir/$file";
}
$type=filetype($cek);
if($type=="dir"){
// kalo tipenya dir, buka..
buka($cek);
} else {
// cek file error_log
if($file=="error_log"){
// jumlah yg ketemu
$num=$num+1;
$ukuran=filesize($dir."/".$file);
$bytes=$bytes+$ukuran;
$ukurannya=format_bytes($ukuran);
if($dir=="./"){
$filenya=$file;
} else {
$filenya="$dir/$file";
}
$echo.="<li>$filenya ($ukurannya ) </li>";
//kalo ketemu, delete
$del=unlink($filenya);
//kalo deleted, naikkan value $num
if($del){
$deleted=$deleted+1;
$bytesdel=$bytesdel+$ukuran;
}
}
}
}
}
closedir($dh);
}
}
}// end function
function format_bytes($bytes) {
if ($bytes < 1024) return $bytes.' B';
elseif ($bytes < 1048576) return round($bytes / 1024, 2).' KB';
elseif ($bytes < 1073741824) return round($bytes / 1048576, 2).' MB';
elseif ($bytes < 1099511627776) return round($bytes / 1073741824, 2).' GB';
else return round($bytes / 1099511627776, 2).' TB';
}
?>
Dobby and Luna have been part of our lives for the past years. They have…
In the year 2021, I've completed some paid projects. Some of them are more technical,…
Based on the GlassTime Bootstrap template, here I present glassmorphism WordPress Theme free to download.This…
This HTML5 template is using Glassmorphism UI design language which is now trending for 2021…
KecamatanKode POSBanjar81152Buleleng81119Busungbiu81154Gerokgak81155Kubutambahan81172Sawan81171Seririt81153Sukasada81161Tejakula81173Klik pada nama kecamatan untuk melihat daftar desa masing-masing. Sumber: kodepos.andiim3.com
Ada yang bilang "semuanya akan mati matic pada akhirnya". Bener aja, sekarang tuntutan transportasi sehari-hari…
This website uses cookies.