PHP Session Clustering

The high availability of your PHP application can be achieved by implementing PHP sessions clustering in the cloud. To successfully handle application server failover we create an environment with Memcached, several Apache servers, and an NGINX load balancer:

1. Log into the  Apiqcloud Dashboard

2. Click the Create environment button

3. In the Environment topology window choose two or more servers you want to use (for example, two instances of Apache) and Memcached Node. Type the name of the environment and click Create.

How It Works:-  
When each session request is completed, the session is sent to the Memcached node for the backup.  This session remains available on the original application server and can be used for serving the next request. After the second request completion, the session is updated in the Memcached.

If the original server fails, the next request is routed to another application server. The newly requested server is asked for the session it doesn't know. So this new server will find the needed session in the Memcached Node. It is identified according to the ID that was appended to the sessionID while session creation. As a result, the server can fetch the session from the Memcached Node.

When the server answers the request, it also updates the session in the Memcached Node. Thus there is no interruption of the app caused by the original server failure - the failover is successfully handled.

At the same time, the NGINX load balancer is distributing traffic across the cluster containing HTTP resources. You can check the load balancing in the Apiqcloud cloud using different load balancing tools.

How to Configure:-

1. Navigate to your environment in the dashboard and click the Config button for Apache.

2. In the opened tab go to etc > php.ini

3. Add the next line to Dynamic Extensions:

extension=memcached.so

4. Make the changes in the [Session] block:

session.save_handler = memcached

session.save_path = "< server >:11211"


Note-
      < server > states for Memcached IP or URL which you can find by clicking
Info
      button for the Memcached node in your environment.

5. Save the changes and restart the Apache node.

That's all! Now if one of the instances fails, the users get automatically switched to the other instance in this cluster and never notice any change.

  • PHP Session Clustering
  • 0 Utilisateurs l'ont trouvée utile
Cette réponse était-elle pertinente?

Articles connexes

How to Enable PHP Extensions

1.Click on config button for your app server.  2. Within the opened configuration tab, click...

Deploy PHP Project Via GIT SVN

Deploy PHP Project via GIT/SVN You can host any public or your private PHP project at...

How to Check Change PHP Version in Apiqcloud

How to check PHP Version in Apiqcloud:   After making new Environment click on “Change...

Ion cube Loader

Running Encoded PHP Scripts with ionCube Loader Encoding application sources is a common...

MariaDB PHP connection

Connection to MySQL/MariaDB for PHP MySQL and MariaDB are highly popular open-source...