Re: File locking with PHP functions
| From: | Stuart Dallas | Date: | Mon, 04 Apr 2011 14:34:38 +0000 |
| Subject: | Re: File locking with PHP functions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-312246@lists.php.net to get a copy of this message | ||
On Monday, 4 April 2011 at 15:28, Paul M Foster wrote:
I'd like to know (from someone who knows the internals more than I do)
> whether the following functions lock files and to what extent:
>
> fopen($filename, 'w');
>
> Does this function lock the file from writes until fclose()?
> Does it lock from reads as well?
>
> fopen($filename, 'r+');
>
> Does this function lock the file from writes until fclose()?
> Does it lock the file from reads as well?
>
> file($filename);
>
> Does this function lock the file from writes until finished?
> Does it lock the file from reads as well?
>
> All this is in the context of a Linux/Unix web server.
No, fopen does not lock the file. Check out http://php.net/flock
but be sure to read all of that page because there are some gotchas with using it.
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/