Tag Archives: Semaphore

What Is Wrong With PHP’s Semaphore Extension

Lack of a true Semaphore

sem_release() releases the semaphore if it is currently acquired by the calling process, otherwise a warning is generated.

By far the worst, this limitation makes a whole class of problems much more difficult to solve, and in fact means that PHP’s Semaphore extension, despite the name, is really a mutex (a semaphore with ownership, i.e., only the acquirer may release). Furthermore, it is inconsistent with the behavior of equivalent functions in other languages such as C and Python.

Please see phm\Lock\Semaphore for a kludgy workaround using mutexes, shared memory, and a message queue. Continue reading