php - sem_release(): failed to release key 0xc: Invalid argument


I'm using semaphore to synchronize some parts in my application.

On releasing of the semaphore (sem_release) I'm getting this warning:

sem_release(): failed to release key 0xc: Invalid argument

First I don't know whether the semaphore released, but since I'm not getting "true" as result, I guess it's not releasing.

PHP Version: 5.6.30

ipcs -V => ipcs from util-linux 2.25.2

Here is the semaphore:

key        semid      owner      perms      nsems 
0x0000000c 4124122    myUser      666        3

Here is part of the code (class Synchronization):

if ( !( $this->semaphoreId = sem_get( $this->id, 1 ) ) )
    throw new RuntimeException( 'Error getting Semaphore.');

if ( !sem_acquire( $this->semaphoreId ) )
   throw new RuntimeException( 'Error acquiring Semaphore.');
if ( !sem_release( $this->semaphoreId ) )
    throw new RuntimeException( 'Error releasing Semaphore.');

P.S. I'm getting this error only in my productive environment and I'm not able to reproduce/debug in in my test environment.

I searched on Internet for this error message, but I found nothing.

Does anyone knows what this message means?


  1. The error message does not appear every time the script is running.
  2. I indeed get sometimes the error 'Error acquiring Semaphore' with the similar warining 'sem_acquire(): failed to acquire key 0xc: Identifier removed', BUT not at the same time(day) I get the 'Error releasing Semaphore'
  3. The class above is used all over the place with different keys to synchronize part of application code. I'm not having ANY issues with other keys. And yes, this key "12"/"0xc" is beeing used ONLY in one place and from the same user.
  4. Issues with permission should not occure, because if you check the permisson of the semaphore "0xc" is "666"



Could you follow the steps from the beginning:

  • Getting the semaphoreresource sem_get ( int $key [, int $max_acquire = 1 [, int $perm = 0666 [, int $auto_release = 1 ]]] )
  • Acquiring the semaphorebool sem_acquire ( resource $sem_identifier [, bool $nowait = false ] )

and add sanity checks to make sure that the above function are returning the expected value.

Could you also check if the other part of your application runs under the same user to avoid permission issues.

People are also looking for solutions to the problem: php - Pagination not working for query_posts function (Querying pages)


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.