Printable Version of Topic

Click here to view this topic in its original format

HTMLHelp Forums _ Web Server Configuration _ Locking files within Apache

Posted by: Brian Chandler Jan 25 2009, 02:38 AM

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?


Posted by: Liam Quinn Apr 9 2009, 09:56 PM

You can pass LOCK_SH to flock to acquire a shared lock for reading. Use LOCK_EX for an exclusive lock for writing.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)