Has anyone got a solution for implementing locking in a custom PHP session handler that stores sessions in the database when the database is a MariaDB cluster?
The problem is that the session handler needs to implement locking (the default file based session handler uses flock()). However GET_LOCK isn't supported by MariaDB Galera cluster and MySQL doesn't support nested transactions, so I can't do a SELECT FOR UPDATE because the first transaction commit will release the row.
Lucky databases are pretty good at locking. In Galera when you have an AUTO_INCREMENT column the
auto_increment_incrementandauto_increment_offsetare automagically set to avoid conflicts inserting/ aka creating sessions on those tables.So take a table structure like:
Rough draft (to the extent of my poor php skills):