note 48338 deleted from function.flock by danbrown

From: Date: Mon, 18 May 2009 00:43:30 +0000
Subject: note 48338 deleted from function.flock by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155420@lists.php.net to get a copy of this message
Note Submitter: maciej.trebacz[at]gmail.com ---- I have an idea about race condintions. How about make a seperate check for integrity of file somewhere in the middle of the script ? Let's take a look on this concept: 1. Some init code 2. Read whole using file() or other function 3. Do the rest that script want to do 4. After writing something to file, check for the file integrity. It can be done in several ways, depending on what you're putting to file. I'm doing file database's so it's rather easy. If the file fails this check, open it, lock it and use data read in (2) to rewrite it. Also a good idea will be putting this whole procedure into while...do, so you ensure that the file will be good. 5. Rest of the script It may also not be perfect, but I think it's a very big chance to prevent scripts to mess your files.

« previous php.notes (#155420) next »