if (!flock($fp, LOCK_EX|LOCK_NB, $wouldblock)) { if ($wouldblock) {
As described in the docs , use LOCK_NB to make a non-blocking attempt to obtain a lock, and if it fails, check $wouldblock to make sure something else holds the lock.
Prateek
source share