file access permission? [message #170074] |
Thu, 07 October 2010 18:50 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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
|
|
|