开发者

Query a PHP semaphore without blocking?

开发者 https://www.devze.com 2022-12-15 00:31 出处:网络
Is it possible to query a s开发者_如何学Cemaphore created with sem_get without actually blocking like the sem_acquire function does?

Is it possible to query a s开发者_如何学Cemaphore created with sem_get without actually blocking like the sem_acquire function does?

Cheers, Dan.


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.


Starting from PHP 5.6.1, it supports the $nowait parameter for sem_acquire:

bool sem_acquire ( resource $sem_identifier [, bool $nowait = false ] )
0

精彩评论

暂无评论...
验证码 换一张
取 消