<?php $fp = fopen(‘/tmp/file.lock‘, "a+"); if(flock($fp, LOCK_EX)) { //进行排他型锁定 fwrite($fp, "lock success\n"); fflush($fp); //flush output before releasing the lock flock($fp, LOCK_UN); //释放锁定 } else { echo "文件正在被其他进程占用"; } fclose($fp); ?>
时间: 2024-12-16 12:40:18