untagged – Is WordPress really not thread-safe?


Take a look at this pseudo code:

$b = SELECT balance FROM accounts WHERE user="john"
$b -= 10
UPDATE account SET balance=$b WHERE user="john"

The code draws 10 dollars from the bank account from John. But if you don’t use a transaction nor a mutex and the code runs two times simultaneously the balance will only be decreased by 10 instead of 20.

But because the code runs very quickly the risk is low. Also it’s a bad example because the two queries can be combined to one: UPDATE account SET balance=balance-10 WHERE user="john"

So even if you ignore transactions completely the risk that errors happen is low.

I wonder if WordPress really takes this risk? I searched the source code and couldn’t find any transactions nor any exclusive locks like file locks.

I’ve also seen someone has written a library called wp-lock. In the readme it says:

because WordPress is not thread-safe

Does WordPress handle simultaneously requests properly or do they really take the risk?

zomega 3 weeks 2023-05-10T13:04:55-05:00 0 Answers 0 views 0

Leave an answer