Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query a PHP semaphore without blocking?

Is it possible to query a semaphore created with sem_get without actually blocking like the sem_acquire function does?

Cheers, Dan.

like image 586
Dan Avatar asked Dec 21 '09 15:12

Dan


1 Answers

Unfortunately, PHP does not currently support non-blocking semaphores.

If something like this is necessary you can utilize semaphores together with shared memory to create your own non-blocking lock mechanisms.

Use a shared memory variable to mark whether or not a lock exists and then use a semaphore around operations against that variable.

like image 116
Mike Lively Avatar answered Sep 28 '22 08:09

Mike Lively