PHPでログのローテートプログラム
ログのRotateをしたくて、書いたのでメモしておきます。
// 1:ファイル(フルパス),2:残すログの数 // ファイルは /home/user/hoge.yyyymmddを想定 function ($file,$num){ $command = "ls -t $file*"; exec($command,$result,$out); if($out){ // エラー exit(); }else{ foreach($result as $row => $log_file){ if($row >= $num){ if(!unlink($log_file)){ // エラー } } } } }
こんな感じでいいのかなぁー。