Atomically increment a limited value in MySQL and PHP

Sometimes you need to acquire a limited resource in an atomically, concurrent way. This is what semaphores are for. But when this resource is in a MySQL row, apparently there is no straightforward way of doing it. In my case, I had a row with two fields used to limit maximum resource usage: ‘used’ and […]