years ago … 2006-05-12 03:05
you may check this out working with % (percent) of disk usage (log object may comes from pear or just remove the log lines)
// return true on error! // on false: fine :-) function check_disk_free_space($path) { global $oLog; // seconds a time-compare will be OK during the process (if it takes longer) // (limit the number if you have huge file movements to beware crashes // or "disk-full"- errors) $secCmp = 60; // max allowed/free size compare Value $sizeCmp = 92; // windows user get www.cygwin.com $cmd = 'c:/cygwin/bin/df.exe -a '. $path; $now = time(); $_v = array(); static $paths = null; static $sizes = null; static $times = null; if ($paths===null) { $paths = array(); $sizes = array(); $times = array(); } if (($i=array_search($path,$paths)) && (($now-$times[$i]) < $secCmp)) { if($sizes[$i] >= $sizeCmp) { $oLog->log('disc space overflow: '.$sizes[$i].' ('.$sizeCmp.' is max limit!) for path: '.$path, 3); return false; } else { $oLog->log('disc space OK: '.$sizes[$i].'% ('.$sizeCmp.' is max limit!) for path: '.$path, 6); return true; } } $oLog->log('getting free space for: '. $path, 6); $result = exec($cmd, $data, $return); $oLog->log('cmd: '. $cmd, 7); if ($result) { $r = explode(' ', $data[1]); while(list($a,$b) = each($r)) { $b = trim($b); if ( $b != '') { $_v[] = $b; } } $oLog->log($_v, 7); $size = intval($_v[4]); $paths[] = $path; $sizes[] = $size; $times[] = time(); if($size >= $sizeCmp) { $oLog->log('disc space overflow: '.$sizes[$i].' ('.$sizeCmp.' is max limit!) for path: '.$path, 3); return false; } else { $oLog->log('disc space OK: '.$sizes[$i].' ('.$sizeCmp.' is max limit!) for path: '.$path, 6); return true; } } else { $oLog->log('error can not get size', 3); return true; } } check_disk_free_space(getcwd());
Schreibe einen Kommentar
Du musst angemeldet sein, um einen Kommentar abzugeben.