In this 2nd version, I put LOCK_EX in file_put_contents($path,$txt,LOCK_EX); The result is the same. You'll get an empty file if you run two instances 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. ------------------------------------------------------