13 January 2014

What if php threads of processes will execute in parallel and your database queries get executed disorderly and some data gets messed up. An issue that pops into your head every once in a while.

Some examples might be on bigger web application when you have to do longer tasks like building a menu or building an index or even updating same data on multiple occasions. Those long-running operations might break data in database if you run those in parallel.

Never before have I done anything about it, but today I stumbled upon it. Finding the issue was really hard. When I tested it, everything worked. But when I got traffic on the script the added data was just not right. I hope to keep the problem in mind every time I build some script. That doesn't mean that I have to go crazy with it, you just have to consider the odds of parallel requests happening exactly when it can mess something up. I can't say anything about other frameworks / applications, but Drupal has an API for it. Locking mechanisms allows you to skip the operation if it get's called while it is running or wait for it to finish and then run the next one or the same one all over again, I guess it's up to your imagination and need.