Re: File Locking in PHP.
| From: | David Robley | Date: | Tue, 20 Feb 2001 00:15:30 +0000 |
| Subject: | Re: File Locking in PHP. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-40672@lists.php.net to get a copy of this message | ||
On Tue, 20 Feb 2001 08:50, Matthew Toledo wrote:
> Hello, I am just starting to use PHP. I have been using PERL for quite
> some time. I was wondering if there is any specific FILE LOCKING I
> need to implement to keep more than one person from altering a text
> file at the same time.
>
> For instance, in PERL, you use the flock command to set up an advisory
> file lock. Lets say that if I have a web page with a text based
> database, and more than one person wants to write to the file at the
> same time. In perl, if you use flock(FILE, 2). This causes person A
> to wait while person B writes to the file. flock(FILE, 8) unlocks the
> file. Then person A is allowed to write to the file.
>
> Does the perl equivalent of flock happen automatically in PHP?
>
> If not, how do you lock a file?
>
> Is it an advisory lock, or will it cause an error if two people try to
> access the same file at the same time for the same purpose (writing).
>
> Thanks,
The flock() function in PHP seems to do pretty much what you are looking
for - it allows setting a shared or exclusive lock and you can control
blocking while locking (at least according to the manual!)
--
David Robley | WEBMASTER & Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/
AusEinet | http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA