PHP Sessions Clustering

PHP Sessions Clustering with Memcached

PHP sessions clustering improves application availability by storing session backups in Memcached. When one Apache application server fails, another server can retrieve the session and continue serving the user without interruption.

Create the Clustered Environment

1

Open the environment wizard

Sign in to the platform account and click Create environment.

2

Add the required nodes

Choose two or more Apache application-server instances and add a Memcached node. Enter the environment name and click Create.

Create a PHP cluster with Apache and Memcached
Create an environment with multiple Apache servers and a Memcached node.

Memcached acts as a distributed caching engine for the application-server layer. Sticky sessions keep a user on the original server while it is available, and Memcached stores a backup that can be retrieved during failover.

PHP session clustering with Memcached
Memcached stores session backups that other Apache servers can retrieve.

How Session Failover Works

Session request completesThe active Apache server sends the updated session to Memcached as a backup.
Original server continuesThe session remains available on the original application server for the next request.
Server failure occursThe NGINX load balancer routes the next request to another available Apache server.
Session is restoredThe new server identifies and retrieves the required session from Memcached.
Session is updated againAfter responding, the new server stores the latest session state back in Memcached.

NGINX distributes HTTP traffic across the application-server cluster. If the original server becomes unavailable, another server continues the session using the Memcached backup.

Configure PHP Sessions in Memcached

1

Open Apache configuration

Locate the environment in the dashboard and click Config beside the Apache application-server layer.

2

Open php.ini

Navigate to etc → php.ini.

3

Enable the Memcached extension

Add the following line under Dynamic Extensions:

extension=memcached.so
Enable the Memcached PHP extension
Enable the memcached.so extension in php.ini.
4

Configure session storage

Find the [Session] section and set Memcached as the session handler:

session.save_handler = memcached
session.save_path = "<server>:11211"
i

Memcached address

Replace <server> with the Memcached node’s internal IP address or URL. Open the node’s Info panel in the dashboard to find it.

Configure the PHP session save path
Set the Memcached session handler and server address in php.ini.
5

Save and restart Apache

Save the changes and restart the Apache application-server nodes.

Expected Result

PHP sessions are backed up to Memcached. If one Apache instance fails, the load balancer sends users to another instance, which retrieves the stored session and continues serving the application without a visible interruption.

Important Notes

  • Use at least two Apache application-server instances.
  • Add a Memcached node to the same environment.
  • Use the Memcached node’s internal IP address or URL and port 11211.
  • Apply the same PHP session settings to all Apache nodes.
  • Restart the Apache nodes after updating php.ini.
  • Test session continuity by stopping one application-server instance.

Common Issues and Solutions

memcached.so cannot be loadedConfirm that the extension is available for the selected PHP version and application-server stack.
Sessions are lost after failoverCheck the session handler, Memcached address, port 11211, and configuration on every Apache node.
Memcached cannot be reachedUse the internal node IP or URL from the Info panel and verify that the Memcached node is running.
Only one Apache node worksSave the same php.ini settings for all application-server instances and restart the full layer.
Users frequently switch serversReview NGINX sticky-session and backend-health settings while keeping Memcached session backup enabled.