FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » file access permission?
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
file access permission? [message #170074] Thu, 07 October 2010 18:50 Go to next message
Amit Prakash Pawar is currently offline  Amit Prakash Pawar
Messages: 10
Registered: October 2010
Karma: 0
Junior Member
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? [message #170076 is a reply to message #170074] Fri, 08 October 2010 19:28 Go to previous messageGo to next message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(Amit Prakash Pawar)

> 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?

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.

Micah
Re: file access permission? [message #170079 is a reply to message #170076] Fri, 08 October 2010 20:44 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
Michael Fesser wrote:
> .oO(Amit Prakash Pawar)
>
>> 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?
>
> 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.
>
> Micah
Put the file into a database blob, and then use database locking tools.
Re: file access permission? [message #170080 is a reply to message #170074] Fri, 08 October 2010 21:31 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 10/7/2010 2:50 PM, Amit Prakash Pawar wrote:
> 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?

Check out http://us3.php.net/manual/en/function.flock.php.

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.
jstucklex(at)attglobal(dot)net
==================
Re: file access permission? [message #170082 is a reply to message #170079] Fri, 08 October 2010 21:37 Go to previous messageGo to next message
Captain Paralytic is currently offline  Captain Paralytic
Messages: 204
Registered: September 2010
Karma: 0
Senior Member
On Oct 8, 9:44 pm, The Natural Philosopher <t...@invalid.invalid>
wrote:
> Michael Fesser wrote:
>> .oO(Amit Prakash Pawar)
>
>>> 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?
>
>> 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.
>
>> Micah
>
> Put the file into a database blob, and then use database locking tools.

What locking tools are they?
Re: file access permission? [message #170083 is a reply to message #170082] Fri, 08 October 2010 22:34 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
Captain Paralytic wrote:
> On Oct 8, 9:44 pm, The Natural Philosopher <t...@invalid.invalid>
> wrote:
>> Michael Fesser wrote:
>>> .oO(Amit Prakash Pawar)
>>>> 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?
>>> 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.
>>> Micah
>> Put the file into a database blob, and then use database locking tools.
>
> What locking tools are they?

e.g. http://dev.mysql.com/doc/refman/5.0/en/innodb-locks-set.html
Re: file access permission? [message #170084 is a reply to message #170074] Sat, 09 October 2010 03:25 Go to previous messageGo to next message
Peter H. Coffin is currently offline  Peter H. Coffin
Messages: 245
Registered: September 2010
Karma: 0
Senior Member
On Thu, 7 Oct 2010 11:50:07 -0700 (PDT), Amit Prakash Pawar wrote:
> 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?

Start building on top of the cvsclient or svnclient classes by César
Rodas.

--
I once successfully declined a departmental retreat, saying that on
that day I planned instead to advance.
-- Alan J. Rosenthal
Re: file access permission? [message #170085 is a reply to message #170074] Sat, 09 October 2010 09:53 Go to previous message
jussist(at)gmail(dot)com is currently offline  jussist(at)gmail(dot)com
Messages: 1
Registered: October 2010
Karma: 0
Junior Member
On Oct 7, 9:50 pm, Amit Prakash Pawar <amitppawar2...@gmail.com>
wrote:
> 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?

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

Tables:
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.

-jussi
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Can anyone recommend a good debugger & IDE for PHP?
Next Topic: Send .csv file to browser
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 21:23:13 GMT 2024

Total time taken to generate the page: 0.02453 seconds