|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-07-16 09:08 UTC] 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). PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 22:00:02 2025 UTC |
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); } /**