Locking files within Apache |
Locking files within Apache |
Brian Chandler |
Jan 25 2009, 02:38 AM
Post
#1
|
Jocular coder Group: Members Posts: 2,460 Joined: 31-August 06 Member No.: 43 |
I'm using pair.com hosting: FreeBSD / Apache / PHP / Mysql
I have a file included as part of a page (for reference, it's the "Website" section of the following page, basically a list of links to the manufacturer's site: http://imaginatorium.org/shop/appleone.htm -- it's also included in at least one other page). Now I'm going to keep the catalog info in the database, and write out this from one of my admin pages. So I thought I ought to lock the file while I'm writing it, so (presumably?) the server would just wait if the file is in the process of being written. Thus it would not be possible to get a corrupt version if someone is loading the page while I'm writing it. PHP has a file lock function flock(), but this would need the pages including the file to call flock() as well, which I don't want, since they do not need exclusive access for reading. I wonder if there is a "proper" way to do it? Or am I going over the top worrying about it? |
Liam Quinn |
Apr 9 2009, 09:56 PM
Post
#2
|
WDG Founder Group: Root Admin Posts: 52 Joined: 2-August 06 From: Canada Member No.: 1 |
You can pass LOCK_SH to flock to acquire a shared lock for reading. Use LOCK_EX for an exclusive lock for writing.
|
Lo-Fi Version | Time is now: 28th March 2024 - 01:41 PM |