Mutually exclusive flags on file_put_contents?

The documentation for file_put_contents () states the following:

FILE_APPEND

Mutual exclusions with LOCK_EX from the application are atomic and, therefore, there is no reason to lock.

LOCK_EX

Mutual exception using FILE_APPEND.

However, a few lines below I see the following code:

<?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);
?>

So, are the FILE_APPEND and LOCK_EX flags mutually exclusive or not? If so, why do they use it in the example? Is this bad documentation?

Thanks for your input!

+3
source share
2 answers

This is just bad documentation. The manual clearly states:

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);
?>

, , , "" , .

+3

@karim79 , : . # 49329, /, / .

( - , )

+4

Source: https://habr.com/ru/post/1715755/