File locking
by janani[ Edit ] 2010-09-14 11:23:44
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])
where,
Handle
A file system pointer resource that is typically created using fopen().
Operation
* 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.
wouldblock
The optional third argument is set to TRUE if the lock would block .