note 34100 added to function.disk-total-space
| From: | shalless at rubix dot net dot au | Date: | Wed, 16 Jul 2003 12:36:54 +0000 |
| Subject: | note 34100 added to function.disk-total-space | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-52188@lists.php.net to get a copy of this message | ||
My first contribution. Trouble is the sum of the byte sizes of the files in your directories is not
equal to the amount of disk space consumed, as andudi points out. A 1-byte file occupies 4096 bytes
of disk space if the block size is 4096. Couldn't understand why andudi did
$s["blksize"]*$s["blocks"]/8. Could only be because $s["blocks"]
counts the number of 512-byte disk blocks not the number of $s["blksize"] blocks, so it
may as well just be $s["blocks"]*512. Furthermore none of the dirspace suggestions allow
for the fact that directories are also files and that they also consume disk space. The following
code dskspace addresses all these issues and can also be used to return the disk space consumed by a
single non-directory file. It will return much larger numbers than you would have been seeing with
any of the other suggestions but I think they are much more realistic:
function dskspace($dir)
{
$s = stat($dir);
$space = $s["blocks"]*512;
if (is_dir($dir))
{
$dh = opendir($dir);
while (($file = readdir($dh)) !== false)
if ($file != "." and $file != "..")
$space += dskspace($dir."/".$file);
closedir($dh);
}
return $space;
}
----
Manual Page -- http://www.php.net/manual/en/function.disk-total-space.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34100
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34100&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34100&report=yes