Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 199903

Re: [PHP3] .htpasswd From: Sascha Schumann (sas <email protected>)
Date: 03/06/99

On Fri, Mar 05, 1999 at 02:31:29PM +1000, Cameron Just wrote:
> Heres some code we just wrote which adds users to a htpasswd file.
>
> 1. Creates a temp file called $htpasswdfile.".lock"
> 2. If this file exists then it waits until doesn't(This stops the
> occurrence of two people adding at once)

And creates a race, until you find a way to do the check and the creation of
the .lock file atomatically.

> The Lock file never gets written to it's just there to let other processes
> know that the htpasswd file is currently being modified.
> This could be done using semaphores but we didn't want to re-learn them
> just yet :)

Using semaphores is a much better way, because it happens to be an atomic
operation.

$semid = sem_get($semaphore_key);
sem_acquire($semid);
...actions...
sem_release($semid);

-- 

Regards,

Sascha Schumann | Consultant | finger sas <email protected> | for PGP public key

-- PHP 3 Mailing List http://www.php.net/ To unsubscribe send an empty message to php3-unsubscribe <email protected> To subscribe to the digest list: php3-digest-subscribe <email protected> For help: php3-help <email protected> Archive: http://www.php.net/mailsearch.php3 List administrator: zeev-list-admin <email protected>