Help - Search - Members - Calendar
Full Version: Locking files within Apache
HTMLHelp Forums > Programming > Web Server Configuration
Brian Chandler
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
You can pass LOCK_SH to flock to acquire a shared lock for reading. Use LOCK_EX for an exclusive lock for writing.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.