Mac上没有flock,只有shlock

flock锁(Linux上)

man flock

*/1 * * * * flock -xn file.lock -c 'sh whoKnow >> ~/log &'

代码锁

<?php  

$lockfile = '/tmp/mytest.lock';  
  
if(file_exists($lockfile)){  
    exit();  
}else{  
    file_put_contents($lockfile, 1, true);  
}  
  
for($i=0; $i<300; $i++){  
    echo date('Y-m-d H:i:s')."\r\n";  
    sleep(1);  
}  
  
unlink($lockfile);  
?>  

参考

  1. http://linux.die.net/man/1/flock

  2. http://stackoverflow.com/questions/10526651/mac-os-x-equivalent-of-linux-flock1-command

  3. http://blog.csdn.net/u010391029/article/details/46823487


niecprea
871 声望54 粉丝

Hello world!


引用和评论

0 条评论