If two scripts tries to write on a same file simultaneously,problem occurs.To avoid this PHP gives concept called file locking.
Syntax for file locking
bool flock ( resource handle, int operation [, int &wouldblock])
A file system pointer resource that is typically created using fopen().
* LOCK_SH to acquire a shared lock (reader).
* LOCK_EX to acquire an exclusive lock (writer).
* LOCK_UN to release a lock (shared or exclusive).
LOCK_NB operations is used if you don't want flock() to block while locking.
The optional third argument is set to TRUE if the lock would block .