当前位置:网站首页>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');
边栏推荐
- Turn to: CEO of Samsung Electronics: all decisions should start from recognizing yourself
- The ambition of JD instant retailing from 618
- PostgreSQL DBA快速入门-通过源码编译安装
- 使用Live Chat促進業務銷售的驚人技巧
- Time series data augmentation for deep learning: paper reading of a survey
- Niuke.com string deformation
- Endgame P.O.O
- Nlp-d59-nlp game D28 - I think it's OK - stage summary - mentality adjustment
- LeetCode: 137. Number II that appears only once
- Oracle database expdp only exports tables
猜你喜欢
随机推荐
转:三星电子CEO:一切决策都要从认清自己开始
Endgame P.O.O
198. house raiding
获取带参数的微信小程序二维码-以及修改二维码LOGO源码分享
Directly applicable go coding specification
英伟达这篇CVPR 2022 Oral火了!2D图像秒变逼真3D物体!虚拟爵士乐队来了!
Learning Tai Chi Maker - esp8226 (XIII) OTA
[custom endpoint and implementation principle]
[GDB debugging tool] | how to debug under multithreading, multiprocessing and running programs
port 22: Connection refused
latex公式及表格识别
【自定义Endpoint 及实现原理】
The ambition of JD instant retailing from 618
Codeforces Round #392 (Div. 2) D. Ability To Convert
Learn Tai Chi Maker - esp8226 (12) esp8266 multitasking
ThinkPHP 5.0 模型关联详解
Niuke network decimal integer to hexadecimal string
Vidéo courte recommandée chaque semaine: Soyez sérieux en parlant de "métaunivers"
P6698-[balticoi 2020 day2] virus [AC automata, DP, SPFA]
How to locate lock waiting in Dameng database







