note 48338 added to function.flock
| From: | maciej.trebacz | Date: | Mon, 20 Dec 2004 06:50:15 +0000 |
| Subject: | note 48338 added to function.flock | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-82068@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/function.flock.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48338
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48338&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48338&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48338&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48338&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48338&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48338&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48338&report=yes
Search -- http://master.php.net/manage/user-notes.php