Delay PHP read long enough to ensure write
How do I delay a PHP script that writes to a text file and then reads from the same file long enough to make sure changes have been written before I attempt开发者_如何学Python the read?
@symcbean is correct. You need to first close the handle you are working on using fclose. Then open up the read connection. The way PHP works is that it won't move to the next line until the previous line has completed operations. So if you are concerned with the read running after the write, then make sure that is where it is in the code. This is different from java and javaScript where triggers cause pieces of the code to run.
Just flush the file's write buffer and then you should be good to go:
http://us.php.net/manual/en/function.fflush.php
You should learn to use flock (lock a file for writing, reading).
精彩评论