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

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

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

<p>Any magic PHP concurrency wand I should know of?</p>

[{'answer_id': 67010, 'author': 'George Mauer', 'author_id': 5056, 'author_profile': 'https://Stackoverflow.com/users/5056', 'pm_score': 0, 'selected': False, 'text': '<p>Not specifically for this issue but: <a href="http://www.firephp.org/" rel="nofollow noreferrer">FirePHP</a>?</p>\n'}, {'answer_id': 67055, 'author': 'Jordan Mack', 'author_id': 9979, 'author_profile': 'https://Stackoverflow.com/users/9979', 'pm_score': 2, 'selected': False, 'text': '<p>PHP is not a language designed for multi-threading, and I don\'t think it ever will be.</p>\n\n<p>If you need mutex functionality, PHP has a <a href="http://us.php.net/sem" rel="nofollow noreferrer">Semaphore</a> functions you can compile in. </p>\n\n<p>Memcache has no mutex capability, but it can be emulated using the <a href="http://us.php.net/manual/en/function.memcache-add.php" rel="nofollow noreferrer">Memcache::add()</a> method.</p>\n\n<p>If you are using a MySQL database, and are trying to prevent some kind of race condition corruption, you can use the <a href="http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html" rel="nofollow noreferrer">lock tables</a> statement, or use <a href="https://web.archive.org/web/20081219053301/http://dev.mysql.com/doc/refman/5.0/en/ansi-diff-transactions.html" rel="nofollow noreferrer">transactions</a>.</p>\n'}, {'answer_id': 67058, 'author': 'Ryan Doherty', 'author_id': 956, 'author_profile': 'https://Stackoverflow.com/users/956', 'pm_score': 1, 'selected': False, 'text': '<p>You could try pounding on your code with a load test tool that can make multiple requests at the same time. <a href="http://jakarta.apache.org/jmeter/" rel="nofollow noreferrer">Jmeter</a> comes to mind.</p>\n'}]
['https://Stackoverflow.com/questions/66952', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10024/']