Is there anyway to protect a file from a thread while another thread is currently writing to the file, something like mutex or semaphor, perhaps so it works even with windows.
You could try reading the manual. http://www.php.net/manual/en/function.flock.php