当前位置:网站首页>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');
边栏推荐
- Target of cmake command_ compile_ options
- Algorithm - the K row with the weakest combat power in the matrix (kotlin)
- Time series data augmentation for deep learning: paper reading of a survey
- Oracle database listening file configuration
- Endgame P.O.O
- Zero foundation self-study SQL course | sub query
- Niuke network realizes simple calculator function
- How to make social media the driving force of cross-border e-commerce? This independent station tool cannot be missed!
- 二十、处理器调度(RR时间片轮转,MLFQ多级反馈队列,CFS完全公平调度器,优先级翻转;多处理器调度)
- leetcode--字符串
猜你喜欢

Learning Tai Chi Maker - esp8226 (XIII) OTA

Thinkphp5 multi language switching project practice

CDGA|到底怎么才能做好数据治理呢?

LeetCode: 240. 搜索二维矩阵 II

Inspiration from reading CVPR 2022 target detection paper

How to make social media the driving force of cross-border e-commerce? This independent station tool cannot be missed!

如何让社交媒体成为跨境电商驱动力?这款独立站工具不能错过!

Servlet fast foundation building

PhpStrom代码格式化设置

谈谈数字化转型晓知识
随机推荐
PostgreSQL DBA快速入门-通过源码编译安装
Why is LNX of e equal to X
vim的使用
Amazing tips for using live chat to drive business sales
Niuke network decimal integer to hexadecimal string
Leetcode-- string
记录一下MySql update会锁定哪些范围的数据
Algorithm -- find and maximum length k subsequence (kotlin)
文献调研报告
An open source monitoring data collector that can monitor everything
Oracle查看数据文件头SCN信息
Niuke.com string deformation
最新Windows下Go语言开发环境搭建+GoLand配置
PRCT-1400 : 未能执行 getcrshome解决方法
开源一款监控数据采集器,啥都能监控
每周推荐短视频:谈论“元宇宙”要有严肃认真的态度
《MATLAB 神经网络43个案例分析》:第32章 小波神经网络的时间序列预测——短时交通流量预测
When should gridfs be used?
零基础自学SQL课程 | 相关子查询
Oracle数据库监听文件配置