Connecting Tech Pros Worldwide Forums | Help | Site Map

fwrite when out of storage space

BKDotCom
Guest
 
Posts: n/a
#1: Jul 17 '05
I have a problem that has long plagued me:
What is the best way to check if I'm out of space?
I have a file editor application (could apply to anything though).
If the server (Apache on SunOS) is out of diskspace
$fp = fopen($file,'w');
fwrite($fp,$string,strlen($string));
fclose($fp);
creates a nice 0-byte file.. no error or anything.

Do I need to write to a test file and check it's filesize first??
There's gotta be a better way.

This is a server where the log files get out of control and that's out
of my jurisdiction.

Luke Ross
Guest
 
Posts: n/a
#2: Jul 17 '05

re: fwrite when out of storage space


Hi,

BKDotCom wrote:[color=blue]
> I have a problem that has long plagued me:
> What is the best way to check if I'm out of space?
> I have a file editor application (could apply to anything though).
> If the server (Apache on SunOS) is out of diskspace
> $fp = fopen($file,'w');
> fwrite($fp,$string,strlen($string));
> fclose($fp);
> creates a nice 0-byte file.. no error or anything.
>
> Do I need to write to a test file and check it's filesize first??
> There's gotta be a better way.
>
> This is a server where the log files get out of control and that's out
> of my jurisdiction.[/color]

http://uk2.php.net/manual/en/functio...free-space.php

Luke

Default User
Guest
 
Posts: n/a
#3: Jul 17 '05

re: fwrite when out of storage space


BKDotCom wrote:[color=blue]
>
> I have a problem that has long plagued me:
> What is the best way to check if I'm out of space?
> I have a file editor application (could apply to anything though).
> If the server (Apache on SunOS) is out of diskspace
> $fp = fopen($file,'w');
> fwrite($fp,$string,strlen($string));
> fclose($fp);
> creates a nice 0-byte file.. no error or anything.[/color]


Have you tried checking the return from fclose() in this situation? In
C, there usually will be an error return because the file buffers can't
be written. Similarly an explicit fflush() normally indicates error when
the data cannot be physically written to the device.




Brian Rodenborn
BKDotCom
Guest
 
Posts: n/a
#4: Jul 17 '05

re: fwrite when out of storage space


Thanks!
However I have brought shame to my family...
not sure how I missed that... old problem though.. pre ver 4.1

Luke Ross <lukeross@sys3175.co.uk> wrote in message news:<vkcamf3soeul28@corp.supernews.com>...[color=blue]
> Hi,
>
> BKDotCom wrote:[color=green]
> > I have a problem that has long plagued me:
> > What is the best way to check if I'm out of space?
> > I have a file editor application (could apply to anything though).
> > If the server (Apache on SunOS) is out of diskspace
> > $fp = fopen($file,'w');
> > fwrite($fp,$string,strlen($string));
> > fclose($fp);
> > creates a nice 0-byte file.. no error or anything.
> >
> > Do I need to write to a test file and check it's filesize first??
> > There's gotta be a better way.
> >
> > This is a server where the log files get out of control and that's out
> > of my jurisdiction.[/color]
>
> http://uk2.php.net/manual/en/functio...free-space.php
>
> Luke[/color]
BKDotCom
Guest
 
Posts: n/a
#5: Jul 17 '05

re: fwrite when out of storage space


I'm pretty sure the return value was always non-false.
Not like a false value does any good after it's wiped the file.

Default User <first.last@company.com> wrote in message[color=blue]
>
> Have you tried checking the return from fclose() in this situation? In
> C, there usually will be an error return because the file buffers can't
> be written. Similarly an explicit fflush() normally indicates error when
> the data cannot be physically written to the device.
>
> Brian Rodenborn[/color]
Closed Thread