I'm currently trying to read a list of values in a text file, and then at the end, go back to the very beginning and write a new list of values.
I've tried Rewind(file) but that only seems to rewind the reader back to the beginning of the current line. How do I make it rewind all the way back to the beginning of the entire file?
I need to do this because I need this operation synchronized and am using fLock(). And if I close the file and open it again to write, there could potentially be problems in between the closing of the first read, and the opening of the second:
Code: Select all
flock($a)
fopen($a, read)
fclose($a)
// < ---- Not synchronized; Someone else calling this script could potentially open the file
// here.
flock($a)
fopen($a, write)
fclose($a)
Code: Select all
flock($a)
fopen($a, read+write)
// read down list
fRewindBackToBeginningOfFile($a)
// write new list
fclose($a)