Reply to Re: Files getting clobered

Your name:

Reply:


Posted by Gordon Burditt on 05/18/06 22:08

>> There was some disk space issues with my server. As a result any script
>> I had that opened a file for writing would clobber it i.e uncate it to
>> zero length . Since there was no space left on device, nothing would be
>> written to it.
>>
>> Are there any workarounds to this?

Buy a bigger disk?

>> Does opening the r+ or w+ make a
>> difference instead of just w ?

>w and w+ can be dangerous if you have disk space issues because they
>truncate the file on open, without a check if you can write data to
>the file again.

If you're going to truncate the file, that's by itself dangerous
whether or not you can write data to the file.

>So i suggest open with r+ and do a is_writable() (i
>think it will return false if no disk space is avail) just before you

is_writable() should NOT return false if no disk space is available,
since you can still write to the existing portion of the file,
and just because there is disk space when you do is_writable() doesn't
mean there's disk space available when you write.

>attempt to write, if it fails, close the file and no data is lost, if
>it returns true you can ftruncate() the file to start from 0.
>But there can still be issues, like if you dont have enough space to write
>the entire content etc...

I recommend writing a new file (in the same directory as the old one),
and when you've finished it, rename it into place under its proper name.

Gordon L. Burditt

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация