By default, user access session data is stored in files. However, in a clustered server environment, file storage is not very convenient.
Even when files are available to all cluster servers via a networked file system, it may cause data corruption if the session files are not locked from concurrent accesses. Networked file system locks may cause excessive delays.
This class provides an alternative solution by distributing session data storage using a MySQL database. It avoids some of the inconveniences of the concurrent accesses to session data stored in a networked file system.
This class can be used as a replacement to the default PHP session manager class to store and retrieve sessions in distributed MySQL servers.
The class retrieves a list of MySQL server hosts from a configuration file in the INI format.
A random host is picked from the list to connect when it is necessary execute MySQL queries to store, retrieve, update or delete session data.
The MySQL server host connection timeout is set to a configurable value, so the class can skip a busy server and try connecting the next host in the list.
The session data may be stored on multiple servers at once to provide greater redundancy.