Now I am facing a situation that I’m building a website without mysql or any other databases.
After consideration, I choose to use Xml file for configurations and data storage (And actually I have really no choice).
My problem is that if different users read and modify the same xml file at one time, will there be any synchronization problem or other problems?
If there are, is there a solution?
For a simple bullet-board system, how is the performance of xml (compared with the same system using mysql)?
Any tips for improving the performance?
Yes, there will quite possibly be synchronization problems.
Are you deploying on UNIX/Linux? If so, I would do the following. Each time you write a file, create the file with a new temporary filename, in the same directory. Once you’re done, rename the file to be the file you want, overwriting any file that’s already there.
This has the following consequences:
To get rid of junk files you could do a
findcommand fromcrontabto find files older than a day and matching the name schema of your temporary files and delete them.If you really need to lock files (i.e. “read, process, write” should not be interrupted by other processes) then you can use some file-locking API offered by the OS. Writing temporary “lock” files is dangerous, as if your process crashes, then they will stay around forever, and then nothing will be able to write to the file.