php – file_put_contents上的互斥标志?

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – file_put_contents上的互斥标志?脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
file_put_contents()文档中,它说明如下:

FILE_APPEND:

LOCK_EX:

然而,下面的几行代码我看到以下代码

<?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标志是否相互排斥?如果是,为什么他们在示例中使用它?这是一个糟糕的文件案例吗?

感谢您的输入!

解决方法

那只是糟糕的文档. manual clearly states

你说的例子是:

<?PHP
$file = 'people.txt';
// The new person to add to the file
$person = "John Smith\n";
// Write the contents to the file,FILE_APPEND | LOCK_EX);
?>

看起来编写这个例子的人误解了“互相排斥”的含义,或者产生了一些秘密的,无证件的行为.

脚本宝典总结

以上是脚本宝典为你收集整理的php – file_put_contents上的互斥标志?全部内容,希望文章能够帮你解决php – file_put_contents上的互斥标志?所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。