Tools to test/debug/fix PHP concurrency issues

Mar 12, 2012   //   by phpfreelancer.biz   //   Blog, PHP Tutorial  //  No Comments

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.

Let me explain for this. 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.

Leave a comment

Share This Post

RSS Wordpress News