#24677 [Com]: [PEAR] File::readAll() does not close file handle after reading
| From: | pmjones at ciaweb dot net | Date: | Tue, 30 Sep 2003 17:40:27 +0000 |
| Subject: | #24677 [Com]: [PEAR] File::readAll() does not close file handle after reading | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-22228@lists.php.net to get a copy of this message | ||
ID: 24677
Comment by: pmjones at ciaweb dot net
Reported By: pjones at ciaweb dot net
Status: Assigned
Bug Type: PEAR related
Operating System: OpenBSD 3.1
PHP Version: Irrelevant
Assigned To: coredumb
New Comment:
Sorry to take so long to get back to you. Applied the
patch, does not appear to work. Using File::readAll()
on a file the first time gives a notice "Undefined
variable 'lock' at line 360 in File.php'" but reads the
file OK. Using it subsequently on the same file, it
goes into an infinite loop with "WARNING [feof(): 7 is
not a valid File-Handle resource] in file [/usr/local/
share/pear/File.php] at line [209]".
Previous Comments:
------------------------------------------------------------------------
[2003-07-31 04:24:57] nicos@php.net
That should fix it?
Can anyone take a look at it?
Index: File.php
===================================================================
RCS file: /repository/pear/File/File.php,v
retrieving revision 1.24
diff -u -u -r1.24 File.php
--- File.php 28 Jan 2003 11:19:27 -0000 1.24
+++ File.php 31 Jul 2003 09:23:38 -0000
@@ -173,7 +173,7 @@
}
$file .= $tmp;
}
-
+ File::close($filename);
return $file;
}
@@ -352,15 +352,21 @@
* @param string $mode Mode the file was opened in
* @return mixed PEAR Error on error, true otherwise
*/
- function close($filename, $mode)
+ function close($filename, $mode = FILE_MODE_READ)
{
- if (!PEAR::isError($fp = &File::_getFilePointer($filename,
$mode))) {
- $filePointers = &PEAR::getStaticProperty('File',
'filePointers');
+ $filePointers = &PEAR::getStaticProperty('File',
'filePointers');
+
+ if (!isset($filePointers[$filename]) OR
!is_resource($filePointers[$filename])) {
+ if (PEAR::isError($fp = &File::_getFilePointer($filename,
$mode, $lock))) {
+ return $fp;
+ }
+ } else {
+ $fp = &$filePointers[$filename];
+ }
+ if(isset($filePointers[$filename][$mode])) {
unset($filePointers[$filename][$mode]);
- return fclose($fp) ? true : PEAR::raiseError('Failed to
close file: ' . $filename);
}
-
- return $fp;
+ return fclose($fp) ? true : PEAR::raiseError('Failed to close
file: ' . $filename);
}
/**
------------------------------------------------------------------------
[2003-07-16 09:08:18] pjones at ciaweb dot net
Description:
------------
When using File::readAll() to read the entire contents
of the same file more than once in the same script, the
first readAll() returns the contents properly, but
subsequent readAll() calls do not. I think this is
because readAll() does not close the file handle when
the method is complete (it leaves the file handle open,
thus locking the file off from subsequent access).
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=24677&edit=1