问题
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