RE: [PHP] File locking in PHP
| From: | Colin McKinnon | Date: | Mon, 02 Oct 2000 11:27:10 +0000 |
| Subject: | RE: [PHP] File locking in PHP | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-18267@lists.php.net to get a copy of this message | ||
At 10:35 29/09/00 -0700, Mark Peoples wrote:
>assuming you're on some sort of nixen, create a file in /tmp of the name of
>the file you're locking, eg, mytextdb.dat . In your other scripts that
>access the file, make sure that that file doesn't exist. if it does, don't
>do anything, if it doesn't, have them perform as they should. when you're
>scripts are done, have them delete the file
Ideally the lock file creation should be atomic. A better method might be
to use 'lockfile' if it is available e.g.
$result=exec("lockfile -1 -r2 /var/lock/php_db");
HTH
Colin