Question

documentation, il est dit sur le file_put_contents () ce qui suit:

FILE_APPEND :

  

Incompatible avec LOCK_EX depuis   ajouter ses sont atomiques et donc il y a   aucune raison de bloquer.

LOCK_EX :

  

Incompatible avec FILE_APPEND.

Et pourtant, quelques lignes beugler je vois le code suivant:

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

Alors, sont les drapeaux FILE_APPEND et LOCK_EX mutuellement exclusifs ou non? Si oui, pourquoi utilisent-ils dans l'exemple? Est-ce un cas de mauvaise documentation?

Merci pour vos commentaires!

Était-ce utile?

La solution

C'est tout simplement mauvaise documentation. manuel indique clairement :

  

FILE_APPEND: Si le nom de fichier de fichier   existe déjà, ajoutez les données à la   fichier au lieu de le remplacer.   Exclusif avec LOCK_EX Mutually depuis   ajouter ses sont atomiques et donc il y a   aucune raison de bloquer.

     

LOCK_EX: un verrou exclusif   dans le dossier tout en procédant à la   l'écriture. Mutuellement exclusif avec   FILE_APPEND.

Et l'exemple que vous parlez de:

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

On dirait que la personne qui a codé l'exemple mal compris le sens de « mutuellement exclusifs », ou qui produit un secret, bahaviour sans papier.

Autres conseils

Comme @ karim79 dit , ce fut une erreur dans la manuel: voir bug # 49329 , qui je l'ai signalé après avoir vu cette question / réponse et a été corrigé / fermé il y a quelques minutes.

(Il faudra un certain temps pour se refléter dans la version en ligne du manuel, mais AHS été corrigé dans ses sources)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top