【发布时间】:2010-11-21 20:26:28
【问题描述】:
在file_put_contents() 文档中,它说如下:
FILE_APPEND:
自 LOCK_EX 互斥 附加是原子的,因此有 没有理由锁定。
LOCK_EX:
与 FILE_APPEND 互斥。
然而,下面几行我看到了以下代码:
<?php
$file = 'people.txt';
// The new person to add to the file
$person = "John Smith\n";
// Write the contents to the file,
// using the FILE_APPEND flag to append the content to the end of the file
// and the LOCK_EX flag to prevent anyone else writing to the file at the same time
file_put_contents($file, $person, FILE_APPEND | LOCK_EX);
?>
那么,FILE_APPEND 和 LOCK_EX 标志是否互斥?如果是,为什么他们在示例中使用它?这是不是文档错误的案例?
感谢您的意见!
【问题讨论】:
-
不仔细看,听起来就像编写示例的人不熟悉文档。或者,可能在编写示例后 API 发生了变化,并且没有人更新示例。
-
谢谢马克,+1 我开始怀疑是否有任何我不知道的晦涩原因。
-
这已为bug #52767 正确修复。标志不是互斥的。