note 35978 added to function.link
| From: | kop at meme dot com | Date: | Mon, 22 Sep 2003 01:43:57 +0000 |
| Subject: | note 35978 added to function.link | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-56858@lists.php.net to get a copy of this message | ||
See also:unlink().
On a Unix system the idiom for performing an atomic update to a file, an update where the system
will either see a new file or an old file but never an intermediate, partially written file, is:
$file = 'foo';
$tmp = $file . '.' . uniqid('', TRUE); // on same partition as $file
// Read $file.
// Write new contents into $tmp.
link($tmp, $file); // Deletes old $file.
unlink($tmp); // Cleanup, delete $tmp.
Note: To avoid race conditions due to concurrent access always use flock() on $file.
----
Manual Page -- http://www.php.net/manual/en/function.link.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35978
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35978&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35978&report=yes