I am working on a Project in Raspberry Pi Zero, with apache as web server. The website is in PHP and based on user inputs, it updates a XML file in the server.
There is also a python program program running parallely with the web server. This python program contantsly reads the XML and grabs the values from XML, stores them locally and checks for changes in them and if there is any changes it performs some UART communications with external devices, sometimes based on these external communication from the devices, python also updates the XML.
Python reads the XML every 2 seconds, and the problem is sometimes, when the python is doing the read operation, if the user prodives input and if PHP inserts the new value to the same XML, python crashes. The client wants to reduce the 2 second delay to .1 second, which means Python will be reading fastly and any changes from PHP will crash it.
Is there a way to get somekind of file lock between python and PHP so that, when Python is reading or writing PHP waits and if PHP is writing Python waits. Priority goes to Python above PHP.
Would be better to have an api call first which would suggest if the data is being changed currently and when was the last data changed.
This way you can avoid the crash which is happening due to sharing of the resource
Handling a common XML file between PHP and Python