PHP check if file is in use

2020-03-18 03:17发布

I want to make a flat files database wich 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 readed), if in that moment a 'update' is in progress (that means the file is modified and written), the file gets blank and I loose all the content.

I thaught 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.

标签: php file
2条回答
闹够了就滚
3楼-- · 2020-03-18 03:37

Please Try this It worked on my case....

    if(readyToRead(__FILE__)){
        echo "File is ready to read.";
    } else{
        echo "File is used by somebody else.";
    }

   function readyToRead($file){
       return ((time() - filemtime($file)) > 5 ) ? true : false;
   }
查看更多
登录 后发表回答