fwrite when out of storage space

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • BKDotCom

    fwrite when out of storage space

    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,$str ing,strlen($str ing));
    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

    #2
    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,$str ing,strlen($str ing));
    > 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]



    Luke

    Comment

    • Default User

      #3
      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,$str ing,strlen($str ing));
      > 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

      Comment

      • BKDotCom

        #4
        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@sys31 75.co.uk> wrote in message news:<vkcamf3so eul28@corp.supe rnews.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,$str ing,strlen($str ing));
        > > 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]

        Comment

        • BKDotCom

          #5
          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@com pany.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]

          Comment

          Working...