[PHP] RE: file locking...

2009-03-03 Thread bruce
Hi Dennis...

Thanks for the reply... Here's my solution up to now.. might change in the
future...

The problem:
App has a bunch of clients that need to get a separate/unique list of files
from a master server app. The files are created by the master server
process, and reside on the filesystem behind the server process. (this is a
client/server based app. client sends a request to the server.. the backend
operation of the server fetches the required files, and returns them to the
client app.)

A key issue is that I don't want to run into potential race conditions,
which would result in a given client never being served the files it's
trying to fetch.

Potential Soln:
1) Invoke a form of file locking, with each client processes waiting
   until it gets its lock.
2) Invoke some form of round-robin process, where the master process
   puts files in different dirs, so each client can have a better
   chance of getting a lock for the different dir..

Final Soln: (for now)
I decided to cheat!
I realized that since each client process is essentially unique, I can
create a uniqueId (uuid) for each process. Remember, the client app is
hitting the master server/file process via a webservice. So I have each
client send it's uuid to the master server via the webprocess. this
information is appended to a file, which gives me kind of a fifo approach
for creating unique dirs for each client. the server (on the backend) then
reads the fifo file, for the uuid. in getting the uuid for the 'client', a
master cron process then reads the fifo file, and for each uuid in the file,
creates a tmp dir for the uuid. the master cron process then populates this
dir, with the required files for the given client.

on the client side, the client loops through a wait loop, checking to see if
anything is created/placed in its tmp 'uuid' dir.. if files are there, it
fetches the files, and proceeds..

This approach ensures that a client would never run into a situation where
it might never get files where files are available for processing. in the
event there are no files, the client simply sleeps until there are files..
in the event a client requests files via the sending of the uuid, and the
client dies before getting the files, but the master cron had already placed
them in the uuid dir.. there will be a cleanup process to reabsorb those
files back into the system...

thanks to all who gave input/pointers!!

thoughts/comments/etc...



-Original Message-
From: python-list-bounces+bedouglas=earthlink@python.org
[mailto:python-list-bounces+bedouglas=earthlink@python.org]on Behalf
Of Dennis Lee Bieber
Sent: Sunday, March 01, 2009 11:41 AM
To: undisclosed-recipients:
Subject: Re: file locking...


On Sun, 1 Mar 2009 10:00:54 -0800, bruce bedoug...@earthlink.net
declaimed the following in comp.lang.python:


 Except in my situation.. the client has no knowledge of the filenaming
 situation, and i might have 1000s of files... think of the FIFO, first in,
 first out.. so i'm loking for a fast solution that would allow me to
create
 groups of say, 500 files, that get batched and processed by the client
 app...

My silly thoughts...

Main process creates temp/scratch directories for each subprocess;
spawn each subprocess, passing the directory path to it;
main process then just loops over the files moving them, one at a time,
to one of the temp/scratch directories, probably in cyclic order to
distribute the load;
when main/input directory is empty, sleep then check again (or, if the
OS supports it -- use some directory change notification) for new files.

Each subprocess only sees its files in the applicable temp/scratch
directory.
--
WulfraedDennis Lee Bieber   KD6MOG
wlfr...@ix.netcom.com   wulfr...@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff:   web-a...@bestiaria.com)
HTTP://www.bestiaria.com/
--
http://mail.python.org/mailman/listinfo/python-list


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: File Locking during *other* file operations

2004-12-17 Thread Jason Barnett
Gerard Samuel wrote:
Im talking about file locking during deleting, and moving
files.
Is it possible to perform file locking for these file operations?
If so, can you provide psuedo code.
Thanks
Sure... just acquire the exclusive lock like you would for writing to a 
file, but do the delete / move instead.  Your apps must actually try to 
flock before *every* file operation though if you expect the locking 
system to work.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: File locking file_[get|put]_contents

2004-12-15 Thread Jason Barnett
Gerard Samuel wrote:
I was wondering.
Does file_get_contents() or file_put_contents() utilise
any kind of file locking?
Thanks
Not that I am aware of (I haven't checked source on this so someone 
correct me if I'm wrong here).  file_get_contents() is a shortcut for 
using the functions fopen, fgets and fclose.  So if you need file 
locking you'll have to flock.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: File locking file_[get|put]_contents

2004-12-15 Thread Gerard Samuel
Jason Barnett wrote:
Gerard Samuel wrote:
I was wondering.
Does file_get_contents() or file_put_contents() utilise
any kind of file locking?
Thanks

Not that I am aware of (I haven't checked source on this so someone 
correct me if I'm wrong here).  file_get_contents() is a shortcut for 
using the functions fopen, fgets and fclose.  So if you need file 
locking you'll have to flock. 

Thats what I figured.  It would have been nice to have an option
to lock with those functions.
Thanks for your reply...
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: File locking in PHP???

2004-07-15 Thread Manuel Lemos
Hello,
On 07/15/2004 12:28 PM, Scott Fletcher wrote:
Hi!  I saw the php function flock(), since I never used it before so I
thought I would ask you folks a couple of questions.
1) Is this function good or is there a better function somewhere that I'm
not aware of?
It depends on what you want to do. There are also semaphores at least 
under Unix systems.


2) If the flock() activated the file lock then is it possible that I
manually unlock the file?  Like chmod or something through the Linux console
for example.
Externally? Only when the file is close or the program that opened is ended.

3) good example of script just in case..
You may want to take a look at this arbitrary content caching class. It 
uses file locks to prevent that multiple scripts attempt to access a 
cache file when it is being updated.

http://www.phpclasses.org/filecache
--
Regards,
Manuel Lemos
PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/
Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php