当前位置:网站首页>PHP file lock
PHP file lock
2022-06-24 09:45:00 【BigChen_ up】
cpu The thread of : It means how many things can be done at the same time .Resources are exclusive : A resource can only be used by one thread at a time , You need to add Exclusive lock , To prevent others from using .Shared lock : A resource can be viewed by many people , But you can't change it when checking .
// When writing documents , You need to add Exclusive lock , There is a disorder in placing other threads to write at the same time
function put($path, $data) {
$handle = fopen($path, 'w');
//flock(); Lock . Parameters 2 Represents the type of lock .
//LOCK_EX: Exclusive lock
if (flock($handle, LOCK_EX)) {
// Write content
fwrite($handle, $data);
//LOCK_UN: Unlock
flock($handle, LOCK_UN);
}
fclose($handle);
}
// Shared lock : When the document is read , Other threads can only read and cannot change
function get($path) {
$handle = fopen($path, 'r');
//LOCK_SH: share share
if (flock($handle, LOCK_SH)) {
//fread() Read by byte
$text = fread($handle, filesize($path));
// Unlock
flock($handle, LOCK_UN);
}
fclose($handle);
return $text;
}
// echo get('d:/php7.0/php.ini');
put('abc.txt', 'AAAAAAAAAAA');
边栏推荐
猜你喜欢
![[bug] @jsonformat has a problem that the date is less than one day when it is used](/img/09/516799972cd3c18795826199aabc9b.png)
[bug] @jsonformat has a problem that the date is less than one day when it is used

R ellipse random point generation and drawing

5分钟,客服聊天处理技巧,炉火纯青

grpc本地测试联调工具BloomRPC

Ggplot2 color setting summary

英伟达这篇CVPR 2022 Oral火了!2D图像秒变逼真3D物体!虚拟爵士乐队来了!

Zero foundation self-study SQL course | having clause

Summary of medical image open source datasets (II)

如何解决独立站多渠道客户沟通难题?这款跨境电商插件一定要知道!

CF566E-Restoring Map【bitset】
随机推荐
获取带参数的微信小程序二维码-以及修改二维码LOGO源码分享
Oracle database listening file configuration
正则匹配手机号
转:三星电子CEO:一切决策都要从认清自己开始
从618看京东即时零售的野心
Reasons for the failure of digital transformation and the way to success
深度学习论文阅读目标检测篇(七)中英对照版:YOLOv4《Optimal Speed and Accuracy of Object Detection》
P6698-[balticoi 2020 day2] virus [AC automata, DP, SPFA]
R ellipse random point generation and drawing
如何提高网络基础设施排障效率,告别数据断档?
LeetCode: 137. Number II that appears only once
Thinkphp5 multi language switching project practice
算法---矩阵中战斗力最弱的 K 行(Kotlin)
可直接套用的Go编码规范
《MATLAB 神经网络43个案例分析》:第32章 小波神经网络的时间序列预测——短时交通流量预测
ThinkPHP 5.0 模型关联详解
vim的使用
PTA monkey chooses King (Joseph Ring problem)
达梦数据库如何定位锁等待问题解决方法
How to make social media the driving force of cross-border e-commerce? This independent station tool cannot be missed!