How to ensure data consistency in WordPress

No, you are not missing something. But you are using the wrong “framework” (which WordPress is not) for your use case, it seems. And you are mixing things up. What you are talking about, A.C.I.D. transactions, is by no means what you think it is for.

  • ACID: save crash recovery (due to soft- or hardware fails)
  • Locking: Exclusive writes to rows and other parts

Both can be done by using the databases that WordPress supports … with the right engine:

  • MySQL: InnoDB
  • MariaDB: XtraDB (an InnoDB fork)

Take a look at InnoDB Locking for more details.

The alternative is to have either hard disk locks (write a LOCK file to disk) or, if you are in the same request, then use a software lock (a variable or constant that you switch to TRUE/FALSE). The third option would be to set the lock natively in the database.

More information in this answer here on the site.

Leave a Comment