How to unit test concurrent read/write with PHPUnit?
<p>I recently encountered an issue on a live application.
I realized I had more and more concurrency exceptions and locks with a database.</p>

<p>Basically I start a transaction which requires a <code>SELECT</code> and an <code>INSERT</code> on the same table to commit.</p>

<p>But because the load is really heavy, each transactions locks the table, in most case it is so fast it doesn't cause any problems but there is a point where the locks start waiting more and more.</p>

<p>I was able to somewhat fix this problem by tweaking the queries.</p>

<p>Though, now, I'd like to write some tests with PHPUnit to validate my fix and avoid any regressions.</p>

<p>I was not able to find any materials on how to do this. </p>

<p>Since PHP isn't multi threaded, I've no ideas how I could run concurrent queries in a single test to validate.</p>

<p>Basically, I would like to be able to run multiple calls in a single test to ensure everything is ok.</p>

<p>I know I could try to do some high level tests by directly querying the http server and load the whole application, but since my problem comes from a standalone library I'd rather like to test it against itself.</p>

<p>Any ideas? </p>