标签:lse 系统 fopen nbsp lock 文件锁 echo pre else
阻塞(等待)模式:
1 <?php 2 $fp = fopen("lock.txt", "r"); 3 if(flock($fp,LOCK_EX)) 4 { 5 //.. do something 6 flock($fp,LOCK_UN);//解锁 7 } else { 8 echo ‘lock!‘; 9 } 10 fclose($fp); 11 ?>
非阻塞模式:
<?php $fp = fopen("lock.txt", "r"); if(flock($fp,LOCK_EX | LOCK_NB)) { //..do something flock($fp,LOCK_UN);//解锁 } else { echo "系统繁忙,请稍后再试"; } fclose($fp); ?>
标签:lse 系统 fopen nbsp lock 文件锁 echo pre else
原文地址:https://www.cnblogs.com/dawuge/p/9407960.html