PHP parallel File writes

137 views Asked by At

I have an old application that uses files instead of a DB to store user data in an xml. All totally legacy. Until the migration to a DB has finished, I need support the current state.

The problem is that sometimes (unreproducible) it occurred, that the file contents were not written completely. This caused the xml files to not be complete and therefore to be invalid.

My assumption is, that the server can't handle the amount of parallel file writes.

Note, that parallel does not mean many scripts write one file, but each script that writes the user content writes for one user per call. There are up to 100 calls to the script in peak times.

The script uses the standard fwrite functionality to write an incoming xml string to the file. No appending, just replacing the whole content, which works in the tests. The problem only occurs when a greater amount of users use the application.

Is there a way to queue the file writes or delay the script calls?

Please comment, if the description is insufficient.

0

There are 0 answers