测试/调试/修复PHP并发问题的工具? [英] Tools to test/debug/fix PHP concurrency issues?
问题描述
我发现自己用PHP的memcached做了一些相对高级的事情.考虑和解决由缓存的无锁特性引起的竞争条件和并发问题已经成为一种精神上的努力.
I find myself doing some relatively advanced stuff with memcached in PHP. It's becoming a mental struggle to think about and resolve race conditions and concurrency issues caused by the lock-free nature of the cache.
关于并发(线程,有人吗?),PHP的工具似乎差强人意,所以我想知道是否有解决方案可以正确地测试/调试它.
PHP seems pretty poor in tools when it comes to concurrency (threads, anyone?), so I wonder if there are any solutions out there to test/debug this properly.
我不想等到两个用户请求两个将同时作为并行进程运行的脚本并引起并发问题,这会让我挠头,或者直到它滚滚而来之前我可能都不会注意到一个clusterfsck.
I don't want to wait until two users request two scripts that will run as parallel processes at the same time and cause a concurrency issue that will leave me scratching my head, or that I might not ever notice until it snowballs into a clusterfsck.
我应该知道的任何魔术PHP并发魔杖吗?
Any magic PHP concurrency wand I should know of?
推荐答案
PHP不是为多线程设计的语言,我认为它永远不会.
PHP is not a language designed for multi-threading, and I don't think it ever will be.
如果需要互斥功能,PHP可以提供信号量函数.
If you need mutex functionality, PHP has a Semaphore functions you can compile in.
Memcache没有互斥功能,但是可以使用进行模拟Memcache :: add()方法.
Memcache has no mutex capability, but it can be emulated using the Memcache::add() method.
如果您使用的是MySQL数据库,并试图防止某些竞争条件损坏,则可以使用交易.
If you are using a MySQL database, and are trying to prevent some kind of race condition corruption, you can use the lock tables statement, or use transactions.
这篇关于测试/调试/修复PHP并发问题的工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!