PHP检查文件是否在使用中 [英] PHP check if file is in use

查看:66
本文介绍了PHP检查文件是否在使用中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个平面文件数据库,该数据库将使用.php文件存储网站中的数据.我唯一的问题是,如果当我从平面文件数据库中选择"某项(这意味着已读取文件),并且在那一刻正在进行更新"(这意味着该文件已被修改并写入),该文件将空白,我丢失了所有内容.

I want to make a flat files database which will use .php files to store data from the website. My only problem is that if when I 'select' something from the flatfile database (that means the file is read), if in that moment a 'update' is in progress (that means the file is modified and written), the file gets blank and I lose all the content.

我考虑了一下,检查文件是否正在使用中,如果正在使用,请等待几毫秒,然后再次检查.

I thought about something, to check if the file is in use at the moment, and if it is, to wait a couple of milliseconds and check again.

推荐答案

查看flock() http://php.net/manual/zh/function.flock.php

这篇关于PHP检查文件是否在使用中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆