note 35978 deleted from function.link by didou
| From: | didou@php.net | Date: | Mon, 22 Sep 2003 07:19:22 +0000 |
| Subject: | note 35978 deleted from function.link by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-56872@lists.php.net to get a copy of this message | ||
Note Submitter: kop@meme.com
----
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.