|
楼主 |
发表于 2011-6-15 11:55:47
|
显示全部楼层
Hex 发表于 2011-6-14 12:03
cli 的话每次启动一个 PHP 就是一个新的进程。
根据你的情况看,这个锁不能跨进程。
这应该是 PHP 的运行 ...
hex给我发的网址,我看了下,下面的第一个回帖,有个代码================
LOCK_NB seems to be checked and works fine in Windows, too, in PHP 5.3.3.
For instance, try concurrently running two instances of the following script (via the CLI). The second prints "Didn't quite get the lock..." as expected, whereas w/o the LOCK_NB flag, it just hangs.
<?php
$x = fopen("flocktest.txt", "w");
if (flock($x, LOCK_EX|LOCK_NB)) {
print "No problems, I got the lock, now I'm going to sit on it.";
while (true)
sleep(5);
} else {
print "Didn't quite get the lock. Quitting now. Good night.";
}
fclose($x);
?>
================================
我开启2个cli进程去运行这个代码,如果去掉LOCK_NB这个锁,确实是会阻塞的。
也就是我前面说的,代码里面是要去flock一下,才会被锁住,否则应该就不会被锁住,应该是这样。
|
|