I need to change a single character in a file.
I’d rather not use an auxiliary file like so (pseudo code):
read(theFile)
change(theFile)
write(theFile2)
erase(theFile)
rename(theFile2,theFile)
Since in this way, Some process can require that file when it is actually erased.
Rather, I’d like to operate on that own file, because this way, I count on the server’s os to take care of timing and process access to the file.
You’ll want to use
flockto lock the file. Example based on code from the PHP docs: