Re: [Q] Exec'ing a command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Eric Gorr wrote:

> Hopefully this will be clear.
> 
> I've got a unix command-line app which I will be exec'ing (or some
> other similar command) from a php script.
> 
> The special property of this unix app is that while it executes and
> terminates quickly, only a single instance can be running at any one
> time.
> 
> However, the php script can be called simultaneously and it is
> possible that an invalid attempt to run two or more instances of the
> unix app at the same time could be made.
> 
> Now, one possible solution to this problem is that the php script adds
> it's request to run the unix app to a queue and their is some other
> code which pulls a request off the queue, performs the operation and
> returns the data back to the php script which made the request.
> 
> Are there other solutions that I have not considered?

A lock file.  Your script will lock it when it's running, unlock it when
it's done.  If your script finds the file already locked, it quits. 

In practical terms, your script will check for the existence of the
file. If found, it exits. If not found, it creates it.  And removes it
when it's finished.  
Yes, the check and the creation of the lock file should preferably be
atomic, but when you're in a script language, you can't have it all.


/Per Jessen, Zürich


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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux