This is the 3nd version and it works. It won't corrupt file even if you execute two instances of the scirpt at the same time. ------------------------------------------------------ How to test it (1) delete "data/test.txt" (2) Open two terminals and execute "php read-and-write.php" (3) See the results. ------------------------------------------------------