file access permission?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I want to create simple file program.

Suppose i have 10 users. and file xyz.txt

When 1st user access file he has authority to read and write.
but if at the same time 2nd user try to access this file.
i have to give only read access or put message like wait 1st users
writing some operation.

How to create such program in PHP.

Please tell me which concept i want to use or any reference tutorial?

Re: file access permission?

.oO(Amit Prakash Pawar)

Quoted text here. Click to load it

You might want to have a look at a version control system or things like
that instead. Doing this as a web application is possible as well, but
will cause you a lot of nightmares.


Re: file access permission?

Michael Fesser wrote:
Quoted text here. Click to load it
Put the file into a database blob, and then use database locking tools.

Re: file access permission?

Quoted text here. Click to load it

What locking tools are they?

Re: file access permission?

Captain Paralytic wrote:
Quoted text here. Click to load it


Re: file access permission?

On 10/7/2010 2:50 PM, Amit Prakash Pawar wrote:
Quoted text here. Click to load it

Check out .

But please note - this is ADVISORY LOCKING only - which means it only
works if you consistently use flock() before every request.  And even
then it isn't real clean, because you need to open the file before you
can lock it.

However, if you look in the user notes, you can see examples of using
another file for locking, then access the file.  Still not real clean,
but more workable.

But the real question here is - why are you attempting to do it this
way?  It's the hardest way to get right, and very prone to errors.  A
database would be a much better solution; it's made to lock data.  And
if your data is something like a list, you don't even have to lock the
entire file - just the item you are changing.

A version control system, as Micah pointed out, would also be a good
solution, and maybe better if the file is more of a text document than a
list.  But it would be a bit harder to implement than a simple database.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: file access permission?

On Thu, 7 Oct 2010 11:50:07 -0700 (PDT), Amit Prakash Pawar wrote:
Quoted text here. Click to load it

Start building on top of the cvsclient or svnclient classes by CÚsar

I once successfully declined a departmental retreat, saying that on
that day I planned instead to advance.
              -- Alan J. Rosenthal

Re: file access permission?

Quoted text here. Click to load it

How about just simple database table, in which you track the locking?

filename      |  Contains the filename that is being locked.
user_locking  |  User id that has the file open. If null, not locked.
lock_started  |  Timestamp when lock started.
last_action   |  Timestamp when locking user was active.

When user saves, update all fields to null, or just delete the row. If
user has been inactive for x minutes, clear the lock.

Something similar for queue.
filename     |  Filename that access has been requested.
user_id      |  User id in the queue.
requested    |  Timestamp when access was requested, but denied due to
the locking.


Site Timeline