Tools to test/debug/fix PHP concurrency issues?

吃可爱长大的小学妹 提交于 2019-12-24 04:22:09

问题


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 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.

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.

Any magic PHP concurrency wand I should know of?


回答1:


PHP is not a language designed for multi-threading, and I don't think it ever will be.

If you need mutex functionality, PHP has a Semaphore functions you can compile in.

Memcache has no mutex capability, but it can be emulated using the Memcache::add() method.

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.




回答2:


You could try pounding on your code with a load test tool that can make multiple requests at the same time. Jmeter comes to mind.




回答3:


Not specifically for this issue but: FirePHP?



来源:https://stackoverflow.com/questions/66952/tools-to-test-debug-fix-php-concurrency-issues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!