Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #8043

Re: Files getting clobbered when I run out of disk space

Newsgroups comp.lang.php
Subject Re: Files getting clobbered when I run out of disk space
References <89d3884a-015f-42a7-910f-7c1c77ba68d9@googlegroups.com>
From Anders Wegge Keller <wegge@wegge.dk>
Date 2013-01-08 09:16 +0100
Message-ID <87ehhwf5tr.fsf@huddi.jernurt.dk> (permalink)
Organization SunSITE.dk - Supporting Open source

Show all headers | View raw


faraz@squashclub.org writes:

> 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 truncate it to
> zero length . Since there was no space left on device, nothing would be
> written to it.
> 
> Are there any workarounds to this? Here is some code I came up, but
> it is untested as I currently have disk space on my account:
> 
> /////////////////////////////
> 
> function check_disk_space() {
> 
> global $home_dir;
> 
> $fp = fopen( "$home_dir/cgi-bin/scripts/check_disk_space" , "w" );
> 
> fwrite ($fp, 'hello world' ) ||  die_sub ( 'Error checking for disk space' );
> 
> fclose ($fp) || die_sub ( 'Error checking for disk space' );
> 
> // unlink ( 'check_disk_space' );
> 
> } // end functio

 Use the disk_free_space() function instead. That will give you a
warning in advance, that you use to have your script send you a mail
about the situation. 

 You should also note that your file could end up being clobbered,
even in situations where you could write this test file. If your
payload would grow the file by more than one disk block, and there was
only one free, the dummy file would be written, but the capacity would
still be exceeded, when you write your actual data.

 And finally, as have already been said: It's not the best of times to
handle a full disk, when you have data to write. It's of course better
to avoid loss of already existing data, but you really need to find a
way of avoiding a full disk in the first place.

-- 
/Wegge

Leder efter redundant peering af dk.*,linux.debian.*

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Files getting clobbered when I run out of disk space faraz@squashclub.org - 2013-01-07 15:49 -0800
  Re: Files getting clobbered when I run out of disk space Adam Harvey <usenet@adamharvey.name> - 2013-01-08 01:07 +0000
  Re: Files getting clobbered when I run out of disk space "Peter H. Coffin" <hellsop@ninehells.com> - 2013-01-07 21:47 -0600
  Re: Files getting clobbered when I run out of disk space Anders Wegge Keller <wegge@wegge.dk> - 2013-01-08 09:16 +0100
  Re: Files getting clobbered when I run out of disk space Jerry Stuckle <jstucklex@attglobal.net> - 2013-01-08 10:26 -0500
  Re: Files getting clobbered when I run out of disk space "Twayne" <nobody@devnull.spamcop.net> - 2013-01-08 13:01 -0500
    Re: Files getting clobbered when I run out of disk space "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2013-01-08 23:20 +0100

csiph-web