In what situations can a PHP semaphore be used?

I am wondering what would be a good situation to use semaphore in PHP or in general, trying to expand my horizons.

+3
source share
1 answer

Semaphores are very close to the core of every operating system. When you want to use concurrency, they are a valuable tool. They control, as in traffic, the access of several "consumers" to the same "resources".

For example, suppose you want to write to a log file from different applications, you can use an application that, using semaphores, stops or allows another to write to this file. Thus, each application first polled the semaphore application, and if it is enabled, then write to the file.

If you need more information / examples, see here:

http://www.experiencefestival.com/semaphore_programming_-_c_semaphore

Semaphores and concurrent programming

http://programmingexamples.wikidot.com/java-semaphore

Hope this helps,

+7
source

Source: https://habr.com/ru/post/1767741/


All Articles