The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

Reply to this topicStart new topic
> Locking files within Apache
Brian Chandler
post Jan 25 2009, 02:38 AM
Post #1

Jocular coder

Group: Members
Posts: 2,298
Joined: 31-August 06
Member No.: 43

I'm using 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: -- 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?

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Liam Quinn
post Apr 9 2009, 09:56 PM
Post #2

WDG Founder

Group: Root Admin
Posts: 51
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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:


- Lo-Fi Version Time is now: 17th June 2018 - 11:07 PM