我无法确切了解// file_lock.php
$filename = "data.txt";
$delay = 5;
$lock = fopen($filename, "w");
if ($lock === FALSE || !flock($lock, LOCK_EX | LOCK_NB, $block) || $block) {
echo "ERROR: Can not open or lock " . $filename . "\n";
sleep($delay);
}
else {
echo "SUCCESS: " . $filename . " locked.\n";
sleep($delay);
flock($lock, LOCK_UN);
echo $filename . " unlocked\n";
}
ed文件的锁定方式。我正在锁定一个简单的文本文件:
is_writable()
然后,从另一个脚本,我检查文件is_readable()
/ // test.php
$filename = "data.txt";
if (is_readable($filename)) echo "File is readable\n";
else echo "File is not readable\n";
if (is_writable($filename)) echo "File is writable\n";
else echo "File is not writable\n";
:
$ php file_lock.php & php test.php
SUCCESS: data.txt locked.
File is readable
File is writable
data.txt unlocked
但是当我运行它们时,他们都认为他们可以访问:
is_readable()
文档here和here在细节上非常缺乏,我缺少什么?我不正确地使用鸡群吗?函数is_writable()
和"Parameter
",Value,Category
, ,
Class1, ,
Blue,50,Bright
Green,0.10,Bright
Purple,0.050,Bright
Yellow,0.50,Bright
White,0.20,Bright
, ,
Class2, ,
Blue,50,Dull
Green,0.10,Dull
Purple,0.050,Dull
Yellow,2.0,Dull
White,0.20,Dull
检查与确定读/写能力无关的内容吗?
答案 0 :(得分:1)
文档缺少很多细节,但它们确实包含is_readable()
或is_writable()
上的一个重要细节:
注意:此功能的结果已缓存。见clearstatcache() 了解更多详情。
在致电clearstatcache()
以查看最新信息之前,您需要针对该文件或目录运行is_readable()
。