note 66010 added to function.disk-free-space

From: Date: Fri, 12 May 2006 07:05:14 +0000
Subject: note 66010 added to function.disk-free-space
Groups: php.notes 
Request: Send a blank email to php-notes+get-111156@lists.php.net to get a copy of this message
you may check this out working with % of disk usage (log object may comes from pear or just remove the log lines) , flobee <?php // 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; } /* echo '$return: ' . $return .'<br><pre>'; echo print_r($data); echo '</pre>'; */ } else { $oLog->log('error can not get size', 3); return true; } } check_disk_free_space(getcwd()); ?> ---- Server IP: 66.163.161.117 Probable Submitter: 80.171.105.244 ---- X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_MESSAGE autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.disk-free-space.php Edit -- http://master.php.net/note/edit/66010 Del: integrated -- http://master.php.net/note/delete/66010/integrated Del: useless -- http://master.php.net/note/delete/66010/useless Del: bad code -- http://master.php.net/note/delete/66010/bad+code Del: spam -- http://master.php.net/note/delete/66010/spam Del: non-english -- http://master.php.net/note/delete/66010/non-english Del: in docs -- http://master.php.net/note/delete/66010/in+docs Del: other reasons-- http://master.php.net/note/delete/66010 Reject -- http://master.php.net/note/reject/66010 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#111156) next »