Deleting error_log automatically

I’ve been noticed by my hosting disk space warning, the indicator bar was red. Why? Oh, the disk space was decreased automatically because the error_log is growing up every my scripts executed. So, I have to delete it every time it’s growing up.

Why?

Why error_log appear automatically in my hosting directories? it is because the hosting guy has turned on the error logging, so the error on the php script won’t be displayed when it’s executed, but store the error string into a file named “error_log”.

Why there’s so many of them? Because most of the directories on my hosting has a PHP script inside it.

Why the size of them are so big for a file? Well, frankly, there are some error inside the PHP engine used by my hosting server and it is not fixed yet until now. Unfortunately, every time a script executed, the size of error_log will grow up. Even when you deleted the file, the file will remain growing up every your site loaded. So, it is important to inspect your directories, and delete error_log frequently.

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?

Of course I am the person who code this script, but you can do that too by using my script,.

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';
}
?>

Money from GA – New Website

horrayyyy…..

I’ve received some money from GA (Google Adsense) two days ago.. It was delivered by WU (Western Union), and I’ve took it at Tejakula Post Office.

Not pretty much, not like other pro publisher.. (Y)

It is only $108.. and only 1.050.000 in IDR (indonesian rupiah)..

I got no idea.. how to spend that amount of money…

So confused… Read More

Facebook Toolbar For You

Are you facebook-addicted like me??

If you do so, keep reading ;-)    If you don’t, just skip it, read another article!!!

Nowadays, people uses FB more than FS (Friendster),  and more people develop their program to suite with FB. Just look at the apps out there, there so many apps that connect to FB. Even there are several mobile java application that connect to FB like Mobile Facebook and Yahoo Go!.

One of them is Facebook Toolbar . If you’re one of the thousands of Facebook users who find themselves constantly signing into and checking your account, this free Firefox add-on is sure to feed your addiction. It offers one-click access to your Facebook account while you browse the Web.

facebook toolbar in action
facebook toolbar in action

Facebook Toolbar integrate your Facebook life into your browser. Search Facebook from anywhere using the ‘Search Box’ which allows you to easily search Facebook no matter where you are. Read More

Belajar SEO & Internet Marketing di dekrizky.com

coba deh pikir....!
coba deh pikir....!

Bagi para blogger pemula (seperti saya), tentunya belajar SEO sangatlah wajib-ajib… Soalnya kita mesti mempublikasikan blog kita ke se-antero blogosphere ini.. Biar kagak rugi bikin blog, apalagi udah mahal-mahal beli domain, biar kagak percuma coi…

SEO
SEO

SEO, atau yang dalam bahasa kampung gue kepanjangannya Search Engine Optimization, akan membuat situs kita cepat berada di dalam index sebuah “Search Engine” dan berada dalam SERP (search engine results page) teratas, itupun jika kita menguasai SEO dengan baik. (H)

Dengan menguasai SEO, kita juga bisa me-monetize blog kita dengan program-program Internet Marketing di internet. Seperti halnya program PTC, review, file sharing, dan lain-lain.

Lalu bagaimana cara belajar SEO dan Internet Marketing?? Read More

GAMBAR -yang- CURANG -tentang- BUMI -dapet- AWARD

Hi there….

Mungkin kalian pada bingung liat judul postingan kali ini… Agak aneh memang… Tapi jangan khawatir, andi belum mulai stress gara-gara Unas kok.. :-P   Ini karena kali ini gw bakal nulis tentang empat hal yang ditulis dengan uppercase di atas…

1. GAMBAR…

Tadi gw coba-coba browsing tentang manipulasi gambar… eh tau-tau dapet link situs tempat editing gambar online…

And hasilnya keren bo… Banyak tool lain yang punya efek berbeda. Dan tentunya GRATIS donk….

ini contohnya….

Andi in Patriotic Style
Andi in Patriotic Style

I’d love da picts.. Read More

Old Blog Post

Dulu aku punya blog di http://andisetiawan.co.cc/

Isinya ya lumayan banyak. Berhubung domain itu bakal expire, makanya q backup semua data dan pindahin ke tempat baru.

Tapi sayang, ada kesalahan teknis ama hosting provider yang gw pake, jadinya script web yang dulu gw pake (Genosi) ga bisa jalan di tempat yang baru, padahal kalo di coba di localhost (pada laptop) bisa jalan lancar…

Dengan berat hati, gw gak make Genosi lagi buat backup data-data yang dulu, gw bakal make wordpress.

Oh ya, alamat backup blog yang dulu ada di http://old.andisetiawan.com

Silahkan lihat-lihat…

NB: bagi yang dulu merasa sudah posting comment ke artikel-artikel yang lama, comment nya akan hilang karena tidak memungkinkan untuk membackup semua comment..