Search code examples
phpxmlfacebook-chatbot

How is it possible to protect read/write transactions with xml file in php


from facebook chat I got the request and this request change some information in xml file (coding on php). The cod is next:

$participants = simplexml_load_file($fname);
//change,add,delete nodes
$participants->asXML($fname);

For example if request 1 and 2 will read the same xml file with simplexml_load_file at one moment, and after request 1 will put an information in it, the next request will erase with his writing the information of previous request. Is it possible to manage it somehow? For example like transactions in data bases?


Solution

  • You should set file permission to the file to prevent it from writing

    $permission = chmod ("/yourdir/yourfile.txt", 0600);

    // Read and write for owner, nothing for everybody else

    Note :

    You should give the exact file path from the root folder that you can look for.

    Here are the more file permissions