Quota
Boynux edited this page Jul 12, 2013
·
4 revisions
Available since release 1.1.0
Sometimes it may be useful to test what happens when the application runs out of disk space. Since 1.1.0 vfsStream provides the possibility to impose a quota on the overall size of the file structure:
$root = vfsStream::setup();
vfsStream::setQuota(10); // set quota to 10 bytes
// issues a warning: file_put_contents(): Only 10 of 11 bytes written, possibly out of free disk space
$bytesWritten = file_put_contents(vfsStream::url('root/file.txt'), '12345678901');
echo 'Bytes written: ' . $bytesWritten; // displays "Bytes written: 10"
echo $root->getChild('file.txt')->getContent(); // displays "1234567890"
These are the rules for using a quota:
- Only writing through stream functions (i.e.
file_put_contents()
,fwrite()
, etc.) respects the quota. Writing directly onvfsStreamFile
instances is not limited. - If no quota is set disk space is considered to be unlimited.
- Each call to
vfsStream::setup()
orvfsStreamWrapper::register()
will reset the quota to unlimited.