File locking

by janani 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 .

Tagged in:

664
like
0
dislike
0
mail
flag

You must LOGIN to add comments