阻塞(等待)模式:
php
<?php $fp = fopen("lock.txt", "r"); if(flock($fp,LOCK_EX)) { //..處理訂單 flock($fp,LOCK_UN); } fclose($fp); ?>
非阻塞模式:
spa
<?php $fp = fopen("lock.txt", "r"); if(flock($fp,LOCK_EX | LOCK_NB)) { //..處理訂單 flock($fp,LOCK_UN); } else { echo "系統繁忙,請稍後再試"; } fclose($fp); ?>