PHP no wait sem_acquire?
Posted
by
SerEnder
on Stack Overflow
See other posts from Stack Overflow
or by SerEnder
Published on 2011-01-31T23:17:41Z
Indexed on
2011/01/31
23:26 UTC
Read the original article
Hit count: 199
Not a specific code question, but more of a general coding question. I'm trying to use a semaphore in a work project to limit the number of users that can access certain processes at a concurrent time.
From my understanding the following:
$iKey = ftock($sSomeFileLocation,'sOneCharacterString'); //Generate the key
if($sem_id = sem_get($iKey){ //1 user allowed
if(sem_acquire($sem_id)){
//Do the limited process here
sem_release($sem_id);
}
}
The problem that I see here is that if there is already one user who has the semaphore key, then the next user just waits until the first user is done rather than just faulting out. Anyone know of a way that if the max_acquire number has been reached, sem_acquire (or similar) will just return false?
Thanks
© Stack Overflow or respective owner