阻塞(等待)模式:
<?php
$fp = fopen("lock.txt", "r");
if(flock($fp,LOCK_EX))
{
//..处理订单
flock($fp,LOCK_UN);
}
fclose($fp);
?>
非阻塞模式:
<?php
$fp = fopen("lock.txt", "r");
if(flock($fp,LOCK_EX | LOCK_NB))
{
//..处理订单
flock($fp,LOCK_UN);
}
else
{
echo "系统繁忙,请稍后再试";
}
fclose($fp);
?>
|
请发表评论