Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6600389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:36:56+00:00 2026-05-25T18:36:56+00:00

my answer is quite simple: is it possible to use a system_v semaphore in

  • 0

my answer is quite simple:
is it possible to use a system_v semaphore in PHP to solve producer-consumer problem?
I mean, classical prod-cons solution can be found here.

semaphore fillCount = 0; // items produced
semaphore emptyCount = BUFFER_SIZE; // remaining space

procedure producer() {
    while (true) {
        item = produceItem();
        down(emptyCount);
            putItemIntoBuffer(item);
        up(fillCount);
    }
}

procedure consumer() {
    while (true) {
        down(fillCount);
            item = removeItemFromBuffer();
        up(emptyCount);
        consumeItem(item);
    }
}

As you can see a producer increment the fillCount after putting an item in the buffer.
Anyway, as I understood in the php-doc you can only use sem_acquire and sem_release to manipulate semaphore and you cannot call sem_release without having acquired it before.
Do you have any idea of how to workaround this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:36:57+00:00Added an answer on May 25, 2026 at 6:36 pm

    If it’s important, consider using a real message queue server: RabbitMQ, OpenAMQ, ActiveMQ, ZeroMQ, beanstalkd, etc. Using semaphores or other local mechanisms won’t scale beyond a single server.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The problem is quite simple, but I spent too much time searching for answer.
I just gave an answer to a quite simple question by using an extension
I have a quite simple question but the answer is not so easy. I
I believe the answer may be quite simple but i cant find the answer
This is quite simple question but I didn't find an answer: Is there any
I'm sure this is quite simple but I can't find the answer. I'm passing
A quite simple question I can't find a definite answer for. Does the delayed_job
Hey guys, this should be quite simple to answer.... Im using XSB Prolog...trying to
I haven't been able to find the answer to this anywhere (it's quite possible
I know it's been asked around but I haven't found quite the answer yet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.