PHP模拟多进程并发将内容写入文件

来源:互联网 发布:centos源码编译安装 编辑:程序博客网 时间:2024/05/19 14:38
function conWrite($filename, $content){$filename_lock = $filename.'.lock';while(1) {if(file_exists($filename_lock)) {usleep(1000);} else {touch($filename_lock);//加锁$f = fopen($filename, 'w');fwrite($f,$content);fclose($f);unlink($filename_lock);break;}}if(file_exists($filename_lock)) {unlink($filename_lock);}}

原创粉丝点击