11

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

Cheers, Dan.

Dan
  • 5,692
  • 3
  • 35
  • 66

2 Answers2

6

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.

Mike Lively
  • 1,008
  • 1
  • 8
  • 9
1

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

bool sem_acquire ( resource $sem_identifier [, bool $nowait = false ] )
Maxim Masiutin
  • 3,991
  • 4
  • 55
  • 72