PHP信号量可以应用在哪些场景?
我想知道在 PHP 或一般情况下使用信号量的好情况是什么,试图扩大我的视野。
I am wondering what would be a good situation to utilize semaphore in PHP or in general, trying to expand my horizons.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
信号量非常接近每个操作系统的核心。当您想使用并发时,它们是一个很有价值的工具。就像在流量中一样,它们控制多个“消费者”对相同“资源”的访问。
例如,假设您想要从不同的应用程序写入日志文件,您可以使用一个应用程序,该应用程序使用信号量来停止或允许另一个应用程序写入该文件。因此,每个应用程序都会首先轮询“信号量”应用程序,如果允许,然后写入文件。
如果您想了解更多信息/示例,请查看此处:
http://www.experiencefestival.com/semaphore_programming_- _c_semaphore
信号量和并发编程
http://programmingexamples.wikidot.com/java-semaphore
希望有所帮助,
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 multiple "consumers" to the same "resources".
For example, suppose you want to write to a log file from different applications, you could use an application that, using semaphores, stop or allows another one to write into that file. So every app would poll the "semaphore" app first, and, if it is allowed, then write to the file.
If you want more information/examples, please look here:
http://www.experiencefestival.com/semaphore_programming_-_c_semaphore
Semaphores and concurrent programming
http://programmingexamples.wikidot.com/java-semaphore
Hope that helps,