zer*_*kms 28
这个样本是在http://php.net/flock上拍摄的,稍微改了一下,这是一个正确的方法来做你想要的:
$fp = fopen("/path/to/lock/file", "w+");
if (flock($fp, LOCK_EX | LOCK_NB)) { // do an exclusive lock
// do the work
flock($fp, LOCK_UN); // release the lock
} else {
echo "Couldn't get the lock!";
}
fclose($fp);
Run Code Online (Sandbox Code Playgroud)
积分:
/tmp而不是/var/tmp