SlideShare a Scribd company logo
1 of 39
Download to read offline
© All rights reserved. Zend Technologies, Inc.
How to scale PHP applications
by Jan Burkl, Enrico Zimuel
Zend Technologies
http://www.zend.com
jan.burkl@zend.com, enrico@zend.com
30th
October 2010 – PHP Barcelona Conference
© All rights reserved. Zend Technologies, Inc.
About us
● Jan Burkl (jan.burkl@zend.com)
● Senior System Engineer at Zend
Technologies in Stuttgart (Germany)
since 2006
● Enrico Zimuel (enrico@zend.com)
● Senior Consultant & Architect at Zend
Technologies in Milan (Italy) since 2008
● Blog on web dev't: http://www.zimuel.it/blog
© All rights reserved. Zend Technologies, Inc.
Summary
● Scalability of a web application
● How to scale a PHP application
● PHP session management
● Sharing session data using:
▶ Network file system
▶ Database
▶ Memcached
▶ Redis
▶ Zend Server Cluster Manager
© All rights reserved. Zend Technologies, Inc.
Scalability of a web
application
© All rights reserved. Zend Technologies, Inc.
Scalability: general definition
“Scalability is a desirable property of a
system, a network, or a process, which
indicates its ability to either handle
growing amounts of work in a graceful
manner or to be enlarged”
Source: Wikipedia
© All rights reserved. Zend Technologies, Inc.
Scalability of a web application
A web application is scalable when is
able to manage a growing traffic with
additional resources (CPU, RAM)
without software changes
© All rights reserved. Zend Technologies, Inc.
Scale vertically vs. Scale horizontally
● Scale vertically (scale up)
▶ Add resources to a single node in a system
▶ Enhance the server (more CPU, more RAM, etc)
▶ High availability difficult to implement
● Scale horizontally (scale out)
▶ Add mores nodes to a system
▶ More servers, distributing the load
▶ High availability easy to implement
© All rights reserved. Zend Technologies, Inc.
Scale up vs. Scale out
Scale up Scale out
vs.
© All rights reserved. Zend Technologies, Inc.
The web scale out
● As Google taught, the best way to scale an high traffic
web application is horizontally
● No expensive servers to scale horizontally
● We need load balancers to split the traffic
between all the servers
A Google server
© All rights reserved. Zend Technologies, Inc.
A typical load balancer architecture
Load Balancer
Web Servers
Internet
Firewall
© All rights reserved. Zend Technologies, Inc.
How to scale a PHP application?
● The PHP application uses session/local data?
▶ Yes = we have to manage the session/local
data across multiple servers
● Using a persistent load balancer
● Share the session data
▶ No = we can scale very easy (stateless)
● Most of the PHP applications are not stateless,
they use session data
© All rights reserved. Zend Technologies, Inc.
Persistent load balancer
● A client request is assigned always to the same
server (means same session/local data)
● Pros:
▶ No software architecture changes
● Cons:
▶ No fault tolerant, if a server goes down the
session data are lost!
▶ The load balancer is the bottleneck
▶ The persistent load balancer are expensive
© All rights reserved. Zend Technologies, Inc.
Share the session data
● Manage the session data across the servers
● Pros:
▶ Fault tolerant, if a server goes down the load
balancer can user another server
▶ No bottleneck in the load balancer
▶ The stateless load balancer are cheaper
● Cons:
▶ Software architecture changes
© All rights reserved. Zend Technologies, Inc.
PHP session management
© All rights reserved. Zend Technologies, Inc.
Sessions in PHP
● Session support in PHP consists of a way to preserve certain
data across subsequent accesses
● To identify the subsequent accesses, from the same client,
PHP uses a cookie variable (PHPSESSID)
▶ Example: PHPSESSID= tclq3an1ri8dsfiuo43845loo1
● By default, session data are stored in the file system of the
server
● In PHP we manage the session data using the $_SESSION
global variable
© All rights reserved. Zend Technologies, Inc.
PHP session management
● Configure the PHP session management (php.ini directives):
▶ session.name
● name of the session cookie identifier
(PHPSESSID by default)
▶ session.save_handler
● defines the name of the handler which is used
for storing and retrieving data associated with
a session (files by default).
▶ session.save_path
● defines the argument which is passed to the
save handler (with files handler is the path to
store the session data)
© All rights reserved. Zend Technologies, Inc.
Example (PHP sessions using files)
● <?php
session_start();
$_SESSION['user']= 'enrico';
● In session folder (for instance, /tmp) the PHP creates a file
named sess_fvi9r84f14sjel8r28o6aqspr2 (where
fvi9r84f14sjel8r28o6aqspr2 is PHPSESSID) that contains:
user|s:6:"enrico";
© All rights reserved. Zend Technologies, Inc.
Share session data
● How to share PHP sessions between multiple
servers?
▶ Using a Network File System
▶ Using a Database
▶ Using Memcached
▶ Using Redis
▶ Using Zend Server Cluster Manager
▶ etc
© All rights reserved. Zend Technologies, Inc.
session_set_save_handler()
● You can write your PHP session handler using
the session_set_save_handler():
bool session_set_save_handler (
callback $open,
callback $close,
callback $read,
callback $write,
callback $destroy,
callback $gc)
● More info: http://php.net/manual/en/function.session-set-save-handler.php
© All rights reserved. Zend Technologies, Inc.
Session sharing
using NFS
© All rights reserved. Zend Technologies, Inc.
Session sharing using NFS
● Use the default PHP session handler
(session.session_handler= files)
● NFS to store the session data files
(session.save_path= NFS folder)
● Pros:
▶ No changes on the PHP side
● Cons:
▶ Highly inefficient
▶ Not designed for high read/write ratio
▶ Performance problems and data corruptions
© All rights reserved. Zend Technologies, Inc.
Session sharing
using Database
© All rights reserved. Zend Technologies, Inc.
Session sharing using DB
● Use the user PHP session handler
(session.session_handler= user)
● Use the session_set_save_handler() to implement
your db session handler
● Which db?
▶ MySQL
http://www.php.net/manual/en/function.session-set-save-handler.php#81761
▶ Ms SQL Server
● http://www.zimuel.it/blog/?p=402
▶ PostgreSQL, Oracle, etc
© All rights reserved. Zend Technologies, Inc.
Session sharing using DB (2)
● Pros:
▶ Solves the scalability limitation
▶ A lot of best practices available
▶ Wide installation base
▶ DB is (normally) available
● Cons:
▶ Sessions have almost 1:1 read/write ratio
▶ Connection overhead
▶ Single point of failure
▶ Performance bottleneck
© All rights reserved. Zend Technologies, Inc.
Session sharing
using Memcached
© All rights reserved. Zend Technologies, Inc.
Session sharing using Memcached
● Use the memcached PHP session handler
(session.session_handler= memcache)
● Pros:
▶ Native session handler
▶ Very fast (works in RAM)
▶ Can be clustered
● Cons:
▶ No persistent data (it's a caching system)
▶ Cyclic memory (data can be overwritten if the
memory is full)
© All rights reserved. Zend Technologies, Inc.
Session sharing
using Redis
© All rights reserved. Zend Technologies, Inc.
What is Redis?
● Redis is an open-source,
networked, in-memory, persistent,
journaled, key-value data store
(NoSQL).
● It's similar to memcached but the
dataset is not volatile
● Developed by: Salvatore Sanfilippo
● Sponsored by vmware
● http://code.google.com/p/redis/
© All rights reserved. Zend Technologies, Inc.
Session sharing using Redis
● Different PHP extensions for Redis:
▶ Predis, http://github.com/nrk/predis/
▶ Rediska, http://rediska.geometria-lab.net/
▶ redis.php, http://github.com/antirez/redisdotphp
▶ PHPRedis!, http://github.com/owlient/phpredis
● Custom session handler for Redis:
▶ http://github.com/ivanstojic/redis-session-php
© All rights reserved. Zend Technologies, Inc.
Session sharing using Redis (2)
● Pros:
▶ Fast (works in RAM)
▶ Reliable (master-slave replication)
● Cons:
▶ PHP Redis extensions are 0.x version
▶ Custom PHP session handler
▶ Not so scalable* (data are stored in RAM)
▶ No High Availability* (master-slave limitation)
* but Redis developers are working on a Cluster version!
© All rights reserved. Zend Technologies, Inc.
Session sharing
using Zend Server
Cluster Manager
© All rights reserved. Zend Technologies, Inc.
What is Zend Server and Cluster Manager?
● Zend Server is a complete, enterprise-ready
Web Application Server for running and
managing PHP applications that require a
high level of reliability, performance and
security on Linux, Windows or IBM i.
● Zend Server Cluster Manager (ZSCM)
extends the benefits of Zend Server across
large-scale PHP deployments.
● With ZSCM you can build a real PHP cluster
stack.
© All rights reserved. Zend Technologies, Inc.
Session sharing with ZSCM
● Session Clustering Extension
● Session Clustering Daemon (SCD)
● Storage backends: Disk / Memory
● Peer-to-peer protocol to communicate
between nodes
● Session management
with master-backup
architecture
© All rights reserved. Zend Technologies, Inc.
Zend Server Cluster Manager architecture
Load Balancer
MySQL
Firewall
© All rights reserved. Zend Technologies, Inc.
High availability: session cluster
© All rights reserved. Zend Technologies, Inc.
High availability: session cluster (2)
© All rights reserved. Zend Technologies, Inc.
Session cluster with ZSCM
● Pros:
▶ Very Fast
▶ Reliable (data are stored in master-backup
servers)
▶ High Availability
▶ Scalable (session data are stored in all the
nodes of the cluster)
▶ No changes to the PHP code
● Cons:
▶ You need Zend Server on each node of the
cluster
© All rights reserved. Zend Technologies, Inc.
Questions?
© All rights reserved. Zend Technologies, Inc.
Thank you for attending!
More info:
http://www.zend.com
http://phpconference.es

More Related Content

What's hot

OpenStack networking juno l3 h-a, dvr
OpenStack networking   juno l3 h-a, dvrOpenStack networking   juno l3 h-a, dvr
OpenStack networking juno l3 h-a, dvrSim Janghoon
 
Stable OSPF: choosing network type.pdf
Stable OSPF: choosing network type.pdfStable OSPF: choosing network type.pdf
Stable OSPF: choosing network type.pdfGLC Networks
 
Container Network Interface: Network Plugins for Kubernetes and beyond
Container Network Interface: Network Plugins for Kubernetes and beyondContainer Network Interface: Network Plugins for Kubernetes and beyond
Container Network Interface: Network Plugins for Kubernetes and beyondKubeAcademy
 
[225]yarn 기반의 deep learning application cluster 구축 김제민
[225]yarn 기반의 deep learning application cluster 구축 김제민[225]yarn 기반의 deep learning application cluster 구축 김제민
[225]yarn 기반의 deep learning application cluster 구축 김제민NAVER D2
 
ISP Load Balancing with Mikrotik ECMP
ISP Load Balancing with Mikrotik ECMPISP Load Balancing with Mikrotik ECMP
ISP Load Balancing with Mikrotik ECMPGLC Networks
 
[1A6]Docker로 보는 서버 운영의 미래
[1A6]Docker로 보는 서버 운영의 미래[1A6]Docker로 보는 서버 운영의 미래
[1A6]Docker로 보는 서버 운영의 미래NAVER D2
 
Ceph with CloudStack
Ceph with CloudStackCeph with CloudStack
Ceph with CloudStackShapeBlue
 
[GuideDoc] Deploy EKS thru eksctl - v1.22_v0.105.0.pdf
[GuideDoc] Deploy EKS thru eksctl - v1.22_v0.105.0.pdf[GuideDoc] Deploy EKS thru eksctl - v1.22_v0.105.0.pdf
[GuideDoc] Deploy EKS thru eksctl - v1.22_v0.105.0.pdfJo Hoon
 
Ansible Tutorial.pdf
Ansible Tutorial.pdfAnsible Tutorial.pdf
Ansible Tutorial.pdfNigussMehari4
 
IT Automation with Ansible
IT Automation with AnsibleIT Automation with Ansible
IT Automation with AnsibleRayed Alrashed
 
ROS 2 deployment in K8s: DDS Router as WAN comms enabler
ROS 2 deployment in K8s: DDS Router as WAN comms enablerROS 2 deployment in K8s: DDS Router as WAN comms enabler
ROS 2 deployment in K8s: DDS Router as WAN comms enablereProsima
 
[MeetUp][1st] 오리뎅이의_쿠버네티스_네트워킹
[MeetUp][1st] 오리뎅이의_쿠버네티스_네트워킹[MeetUp][1st] 오리뎅이의_쿠버네티스_네트워킹
[MeetUp][1st] 오리뎅이의_쿠버네티스_네트워킹InfraEngineer
 
[OpenStack Days Korea 2016] Track1 - 카카오는 오픈스택 기반으로 어떻게 5000VM을 운영하고 있을까?
[OpenStack Days Korea 2016] Track1 - 카카오는 오픈스택 기반으로 어떻게 5000VM을 운영하고 있을까?[OpenStack Days Korea 2016] Track1 - 카카오는 오픈스택 기반으로 어떻게 5000VM을 운영하고 있을까?
[OpenStack Days Korea 2016] Track1 - 카카오는 오픈스택 기반으로 어떻게 5000VM을 운영하고 있을까?OpenStack Korea Community
 
DCSF 19 Deploying Rootless buildkit on Kubernetes
DCSF 19 Deploying Rootless buildkit on KubernetesDCSF 19 Deploying Rootless buildkit on Kubernetes
DCSF 19 Deploying Rootless buildkit on KubernetesDocker, Inc.
 

What's hot (20)

OpenStack networking juno l3 h-a, dvr
OpenStack networking   juno l3 h-a, dvrOpenStack networking   juno l3 h-a, dvr
OpenStack networking juno l3 h-a, dvr
 
Stable OSPF: choosing network type.pdf
Stable OSPF: choosing network type.pdfStable OSPF: choosing network type.pdf
Stable OSPF: choosing network type.pdf
 
Container Network Interface: Network Plugins for Kubernetes and beyond
Container Network Interface: Network Plugins for Kubernetes and beyondContainer Network Interface: Network Plugins for Kubernetes and beyond
Container Network Interface: Network Plugins for Kubernetes and beyond
 
[225]yarn 기반의 deep learning application cluster 구축 김제민
[225]yarn 기반의 deep learning application cluster 구축 김제민[225]yarn 기반의 deep learning application cluster 구축 김제민
[225]yarn 기반의 deep learning application cluster 구축 김제민
 
ISP Load Balancing with Mikrotik ECMP
ISP Load Balancing with Mikrotik ECMPISP Load Balancing with Mikrotik ECMP
ISP Load Balancing with Mikrotik ECMP
 
Scaling PHP apps
Scaling PHP appsScaling PHP apps
Scaling PHP apps
 
[1A6]Docker로 보는 서버 운영의 미래
[1A6]Docker로 보는 서버 운영의 미래[1A6]Docker로 보는 서버 운영의 미래
[1A6]Docker로 보는 서버 운영의 미래
 
Ceph issue 해결 사례
Ceph issue 해결 사례Ceph issue 해결 사례
Ceph issue 해결 사례
 
Ceph with CloudStack
Ceph with CloudStackCeph with CloudStack
Ceph with CloudStack
 
[GuideDoc] Deploy EKS thru eksctl - v1.22_v0.105.0.pdf
[GuideDoc] Deploy EKS thru eksctl - v1.22_v0.105.0.pdf[GuideDoc] Deploy EKS thru eksctl - v1.22_v0.105.0.pdf
[GuideDoc] Deploy EKS thru eksctl - v1.22_v0.105.0.pdf
 
Ansible Tutorial.pdf
Ansible Tutorial.pdfAnsible Tutorial.pdf
Ansible Tutorial.pdf
 
Deploying IPv6 on OpenStack
Deploying IPv6 on OpenStackDeploying IPv6 on OpenStack
Deploying IPv6 on OpenStack
 
BGP filter with mikrotik
BGP filter with mikrotikBGP filter with mikrotik
BGP filter with mikrotik
 
IT Automation with Ansible
IT Automation with AnsibleIT Automation with Ansible
IT Automation with Ansible
 
ROS 2 deployment in K8s: DDS Router as WAN comms enabler
ROS 2 deployment in K8s: DDS Router as WAN comms enablerROS 2 deployment in K8s: DDS Router as WAN comms enabler
ROS 2 deployment in K8s: DDS Router as WAN comms enabler
 
[MeetUp][1st] 오리뎅이의_쿠버네티스_네트워킹
[MeetUp][1st] 오리뎅이의_쿠버네티스_네트워킹[MeetUp][1st] 오리뎅이의_쿠버네티스_네트워킹
[MeetUp][1st] 오리뎅이의_쿠버네티스_네트워킹
 
[OpenStack Days Korea 2016] Track1 - 카카오는 오픈스택 기반으로 어떻게 5000VM을 운영하고 있을까?
[OpenStack Days Korea 2016] Track1 - 카카오는 오픈스택 기반으로 어떻게 5000VM을 운영하고 있을까?[OpenStack Days Korea 2016] Track1 - 카카오는 오픈스택 기반으로 어떻게 5000VM을 운영하고 있을까?
[OpenStack Days Korea 2016] Track1 - 카카오는 오픈스택 기반으로 어떻게 5000VM을 운영하고 있을까?
 
Node js crash course session 1
Node js crash course   session 1Node js crash course   session 1
Node js crash course session 1
 
DCSF 19 Deploying Rootless buildkit on Kubernetes
DCSF 19 Deploying Rootless buildkit on KubernetesDCSF 19 Deploying Rootless buildkit on Kubernetes
DCSF 19 Deploying Rootless buildkit on Kubernetes
 
Ansible
AnsibleAnsible
Ansible
 

Similar to How to scale PHP applications

Costruire un sito e-commerce in alta affidabilità con Magento e Zend Server C...
Costruire un sito e-commerce in alta affidabilità con Magento e Zend Server C...Costruire un sito e-commerce in alta affidabilità con Magento e Zend Server C...
Costruire un sito e-commerce in alta affidabilità con Magento e Zend Server C...Zend by Rogue Wave Software
 
High performance PHP: Scaling and getting the most out of your infrastructure
High performance PHP: Scaling and getting the most out of your infrastructureHigh performance PHP: Scaling and getting the most out of your infrastructure
High performance PHP: Scaling and getting the most out of your infrastructuremkherlakian
 
Quick start on Zend Framework 2
Quick start on Zend Framework 2Quick start on Zend Framework 2
Quick start on Zend Framework 2Enrico Zimuel
 
How to Manage Cloud Infrastructures using Zend Framework
How to Manage Cloud Infrastructures using Zend FrameworkHow to Manage Cloud Infrastructures using Zend Framework
How to Manage Cloud Infrastructures using Zend FrameworkZend by Rogue Wave Software
 
Scalable High-Availability Session Storage with ZSCM
Scalable High-Availability Session Storage with ZSCMScalable High-Availability Session Storage with ZSCM
Scalable High-Availability Session Storage with ZSCMZend by Rogue Wave Software
 
Turbocharging php applications with zend server (workshop)
Turbocharging php applications with zend server (workshop)Turbocharging php applications with zend server (workshop)
Turbocharging php applications with zend server (workshop)Eric Ritchie
 
Turbocharging php applications with zend server
Turbocharging php applications with zend serverTurbocharging php applications with zend server
Turbocharging php applications with zend serverEric Ritchie
 
Zero Downtime JEE Architectures
Zero Downtime JEE ArchitecturesZero Downtime JEE Architectures
Zero Downtime JEE ArchitecturesAlexander Penev
 
Microsoft TechDays 2011 - PHP on Windows
Microsoft TechDays 2011 - PHP on WindowsMicrosoft TechDays 2011 - PHP on Windows
Microsoft TechDays 2011 - PHP on WindowsEnterprise PHP Center
 
Intro to XPages for Administrators (DanNotes, November 28, 2012)
Intro to XPages for Administrators (DanNotes, November 28, 2012)Intro to XPages for Administrators (DanNotes, November 28, 2012)
Intro to XPages for Administrators (DanNotes, November 28, 2012)Per Henrik Lausten
 
Final presentasi gnome asia
Final presentasi gnome asiaFinal presentasi gnome asia
Final presentasi gnome asiaAnton Siswo
 
Zend Server: A Guided Tour
Zend Server: A Guided TourZend Server: A Guided Tour
Zend Server: A Guided TourShahar Evron
 
Building and managing applications fast for IBM i
Building and managing applications fast for IBM iBuilding and managing applications fast for IBM i
Building and managing applications fast for IBM iZend by Rogue Wave Software
 
(phpconftw2012) PHP as a Middleware in Embedded Systems
(phpconftw2012) PHP as a Middleware in Embedded Systems(phpconftw2012) PHP as a Middleware in Embedded Systems
(phpconftw2012) PHP as a Middleware in Embedded Systemssosorry
 
Best Practices in PHP Application Deployment
Best Practices in PHP Application DeploymentBest Practices in PHP Application Deployment
Best Practices in PHP Application DeploymentShahar Evron
 
Zingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHPZingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHPChau Thanh
 
Zingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHPZingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHPVõ Duy Tuấn
 
zingmepracticeforbuildingscalablewebsitewithphp
zingmepracticeforbuildingscalablewebsitewithphpzingmepracticeforbuildingscalablewebsitewithphp
zingmepracticeforbuildingscalablewebsitewithphphazzaz
 
01 zingme practice for building scalable website with php
01 zingme practice for building scalable website with php01 zingme practice for building scalable website with php
01 zingme practice for building scalable website with phpNguyen Duc Phu
 

Similar to How to scale PHP applications (20)

Costruire un sito e-commerce in alta affidabilità con Magento e Zend Server C...
Costruire un sito e-commerce in alta affidabilità con Magento e Zend Server C...Costruire un sito e-commerce in alta affidabilità con Magento e Zend Server C...
Costruire un sito e-commerce in alta affidabilità con Magento e Zend Server C...
 
High performance PHP: Scaling and getting the most out of your infrastructure
High performance PHP: Scaling and getting the most out of your infrastructureHigh performance PHP: Scaling and getting the most out of your infrastructure
High performance PHP: Scaling and getting the most out of your infrastructure
 
Quick start on Zend Framework 2
Quick start on Zend Framework 2Quick start on Zend Framework 2
Quick start on Zend Framework 2
 
How to Manage Cloud Infrastructures using Zend Framework
How to Manage Cloud Infrastructures using Zend FrameworkHow to Manage Cloud Infrastructures using Zend Framework
How to Manage Cloud Infrastructures using Zend Framework
 
Scalable High-Availability Session Storage with ZSCM
Scalable High-Availability Session Storage with ZSCMScalable High-Availability Session Storage with ZSCM
Scalable High-Availability Session Storage with ZSCM
 
Turbocharging php applications with zend server (workshop)
Turbocharging php applications with zend server (workshop)Turbocharging php applications with zend server (workshop)
Turbocharging php applications with zend server (workshop)
 
Turbocharging php applications with zend server
Turbocharging php applications with zend serverTurbocharging php applications with zend server
Turbocharging php applications with zend server
 
Zero Downtime JEE Architectures
Zero Downtime JEE ArchitecturesZero Downtime JEE Architectures
Zero Downtime JEE Architectures
 
Microsoft TechDays 2011 - PHP on Windows
Microsoft TechDays 2011 - PHP on WindowsMicrosoft TechDays 2011 - PHP on Windows
Microsoft TechDays 2011 - PHP on Windows
 
Intro to XPages for Administrators (DanNotes, November 28, 2012)
Intro to XPages for Administrators (DanNotes, November 28, 2012)Intro to XPages for Administrators (DanNotes, November 28, 2012)
Intro to XPages for Administrators (DanNotes, November 28, 2012)
 
Final presentasi gnome asia
Final presentasi gnome asiaFinal presentasi gnome asia
Final presentasi gnome asia
 
Zend Server: A Guided Tour
Zend Server: A Guided TourZend Server: A Guided Tour
Zend Server: A Guided Tour
 
Building and managing applications fast for IBM i
Building and managing applications fast for IBM iBuilding and managing applications fast for IBM i
Building and managing applications fast for IBM i
 
(phpconftw2012) PHP as a Middleware in Embedded Systems
(phpconftw2012) PHP as a Middleware in Embedded Systems(phpconftw2012) PHP as a Middleware in Embedded Systems
(phpconftw2012) PHP as a Middleware in Embedded Systems
 
Best Practices in PHP Application Deployment
Best Practices in PHP Application DeploymentBest Practices in PHP Application Deployment
Best Practices in PHP Application Deployment
 
NodeJs vs PHP
NodeJs vs PHPNodeJs vs PHP
NodeJs vs PHP
 
Zingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHPZingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHP
 
Zingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHPZingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHP
 
zingmepracticeforbuildingscalablewebsitewithphp
zingmepracticeforbuildingscalablewebsitewithphpzingmepracticeforbuildingscalablewebsitewithphp
zingmepracticeforbuildingscalablewebsitewithphp
 
01 zingme practice for building scalable website with php
01 zingme practice for building scalable website with php01 zingme practice for building scalable website with php
01 zingme practice for building scalable website with php
 

More from Enrico Zimuel

Password (in)security
Password (in)securityPassword (in)security
Password (in)securityEnrico Zimuel
 
Integrare Zend Framework in Wordpress
Integrare Zend Framework in WordpressIntegrare Zend Framework in Wordpress
Integrare Zend Framework in WordpressEnrico Zimuel
 
Cryptography with Zend Framework
Cryptography with Zend FrameworkCryptography with Zend Framework
Cryptography with Zend FrameworkEnrico Zimuel
 
Introduzione alla Posta Elettronica Certificata (PEC): le regole tecniche
Introduzione alla Posta Elettronica Certificata (PEC): le regole tecnicheIntroduzione alla Posta Elettronica Certificata (PEC): le regole tecniche
Introduzione alla Posta Elettronica Certificata (PEC): le regole tecnicheEnrico Zimuel
 
A quick start on Zend Framework 2
A quick start on Zend Framework 2A quick start on Zend Framework 2
A quick start on Zend Framework 2Enrico Zimuel
 
Zend Framework 2 quick start
Zend Framework 2 quick startZend Framework 2 quick start
Zend Framework 2 quick startEnrico Zimuel
 
Cryptography in PHP: use cases
Cryptography in PHP: use casesCryptography in PHP: use cases
Cryptography in PHP: use casesEnrico Zimuel
 
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)Enrico Zimuel
 
Manage cloud infrastructures using Zend Framework 2 (and ZF1)
Manage cloud infrastructures using Zend Framework 2 (and ZF1)Manage cloud infrastructures using Zend Framework 2 (and ZF1)
Manage cloud infrastructures using Zend Framework 2 (and ZF1)Enrico Zimuel
 
Framework software e Zend Framework
Framework software e Zend FrameworkFramework software e Zend Framework
Framework software e Zend FrameworkEnrico Zimuel
 
Strong cryptography in PHP
Strong cryptography in PHPStrong cryptography in PHP
Strong cryptography in PHPEnrico Zimuel
 
Velocizzare Joomla! con Zend Server Community Edition
Velocizzare Joomla! con Zend Server Community EditionVelocizzare Joomla! con Zend Server Community Edition
Velocizzare Joomla! con Zend Server Community EditionEnrico Zimuel
 
Zend_Cache: how to improve the performance of PHP applications
Zend_Cache: how to improve the performance of PHP applicationsZend_Cache: how to improve the performance of PHP applications
Zend_Cache: how to improve the performance of PHP applicationsEnrico Zimuel
 
XCheck a benchmark checker for XML query processors
XCheck a benchmark checker for XML query processorsXCheck a benchmark checker for XML query processors
XCheck a benchmark checker for XML query processorsEnrico Zimuel
 
Introduzione alle tabelle hash
Introduzione alle tabelle hashIntroduzione alle tabelle hash
Introduzione alle tabelle hashEnrico Zimuel
 
Crittografia quantistica: fantascienza o realtà?
Crittografia quantistica: fantascienza o realtà?Crittografia quantistica: fantascienza o realtà?
Crittografia quantistica: fantascienza o realtà?Enrico Zimuel
 
Introduzione alla crittografia
Introduzione alla crittografiaIntroduzione alla crittografia
Introduzione alla crittografiaEnrico Zimuel
 
Crittografia è sinonimo di sicurezza?
Crittografia è sinonimo di sicurezza?Crittografia è sinonimo di sicurezza?
Crittografia è sinonimo di sicurezza?Enrico Zimuel
 

More from Enrico Zimuel (20)

Password (in)security
Password (in)securityPassword (in)security
Password (in)security
 
Integrare Zend Framework in Wordpress
Integrare Zend Framework in WordpressIntegrare Zend Framework in Wordpress
Integrare Zend Framework in Wordpress
 
Cryptography with Zend Framework
Cryptography with Zend FrameworkCryptography with Zend Framework
Cryptography with Zend Framework
 
Introduzione alla Posta Elettronica Certificata (PEC): le regole tecniche
Introduzione alla Posta Elettronica Certificata (PEC): le regole tecnicheIntroduzione alla Posta Elettronica Certificata (PEC): le regole tecniche
Introduzione alla Posta Elettronica Certificata (PEC): le regole tecniche
 
A quick start on Zend Framework 2
A quick start on Zend Framework 2A quick start on Zend Framework 2
A quick start on Zend Framework 2
 
Zend Framework 2 quick start
Zend Framework 2 quick startZend Framework 2 quick start
Zend Framework 2 quick start
 
PHP goes mobile
PHP goes mobilePHP goes mobile
PHP goes mobile
 
Zend Framework 2
Zend Framework 2Zend Framework 2
Zend Framework 2
 
Cryptography in PHP: use cases
Cryptography in PHP: use casesCryptography in PHP: use cases
Cryptography in PHP: use cases
 
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
 
Manage cloud infrastructures using Zend Framework 2 (and ZF1)
Manage cloud infrastructures using Zend Framework 2 (and ZF1)Manage cloud infrastructures using Zend Framework 2 (and ZF1)
Manage cloud infrastructures using Zend Framework 2 (and ZF1)
 
Framework software e Zend Framework
Framework software e Zend FrameworkFramework software e Zend Framework
Framework software e Zend Framework
 
Strong cryptography in PHP
Strong cryptography in PHPStrong cryptography in PHP
Strong cryptography in PHP
 
Velocizzare Joomla! con Zend Server Community Edition
Velocizzare Joomla! con Zend Server Community EditionVelocizzare Joomla! con Zend Server Community Edition
Velocizzare Joomla! con Zend Server Community Edition
 
Zend_Cache: how to improve the performance of PHP applications
Zend_Cache: how to improve the performance of PHP applicationsZend_Cache: how to improve the performance of PHP applications
Zend_Cache: how to improve the performance of PHP applications
 
XCheck a benchmark checker for XML query processors
XCheck a benchmark checker for XML query processorsXCheck a benchmark checker for XML query processors
XCheck a benchmark checker for XML query processors
 
Introduzione alle tabelle hash
Introduzione alle tabelle hashIntroduzione alle tabelle hash
Introduzione alle tabelle hash
 
Crittografia quantistica: fantascienza o realtà?
Crittografia quantistica: fantascienza o realtà?Crittografia quantistica: fantascienza o realtà?
Crittografia quantistica: fantascienza o realtà?
 
Introduzione alla crittografia
Introduzione alla crittografiaIntroduzione alla crittografia
Introduzione alla crittografia
 
Crittografia è sinonimo di sicurezza?
Crittografia è sinonimo di sicurezza?Crittografia è sinonimo di sicurezza?
Crittografia è sinonimo di sicurezza?
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 

Recently uploaded (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 

How to scale PHP applications

  • 1. © All rights reserved. Zend Technologies, Inc. How to scale PHP applications by Jan Burkl, Enrico Zimuel Zend Technologies http://www.zend.com jan.burkl@zend.com, enrico@zend.com 30th October 2010 – PHP Barcelona Conference
  • 2. © All rights reserved. Zend Technologies, Inc. About us ● Jan Burkl (jan.burkl@zend.com) ● Senior System Engineer at Zend Technologies in Stuttgart (Germany) since 2006 ● Enrico Zimuel (enrico@zend.com) ● Senior Consultant & Architect at Zend Technologies in Milan (Italy) since 2008 ● Blog on web dev't: http://www.zimuel.it/blog
  • 3. © All rights reserved. Zend Technologies, Inc. Summary ● Scalability of a web application ● How to scale a PHP application ● PHP session management ● Sharing session data using: ▶ Network file system ▶ Database ▶ Memcached ▶ Redis ▶ Zend Server Cluster Manager
  • 4. © All rights reserved. Zend Technologies, Inc. Scalability of a web application
  • 5. © All rights reserved. Zend Technologies, Inc. Scalability: general definition “Scalability is a desirable property of a system, a network, or a process, which indicates its ability to either handle growing amounts of work in a graceful manner or to be enlarged” Source: Wikipedia
  • 6. © All rights reserved. Zend Technologies, Inc. Scalability of a web application A web application is scalable when is able to manage a growing traffic with additional resources (CPU, RAM) without software changes
  • 7. © All rights reserved. Zend Technologies, Inc. Scale vertically vs. Scale horizontally ● Scale vertically (scale up) ▶ Add resources to a single node in a system ▶ Enhance the server (more CPU, more RAM, etc) ▶ High availability difficult to implement ● Scale horizontally (scale out) ▶ Add mores nodes to a system ▶ More servers, distributing the load ▶ High availability easy to implement
  • 8. © All rights reserved. Zend Technologies, Inc. Scale up vs. Scale out Scale up Scale out vs.
  • 9. © All rights reserved. Zend Technologies, Inc. The web scale out ● As Google taught, the best way to scale an high traffic web application is horizontally ● No expensive servers to scale horizontally ● We need load balancers to split the traffic between all the servers A Google server
  • 10. © All rights reserved. Zend Technologies, Inc. A typical load balancer architecture Load Balancer Web Servers Internet Firewall
  • 11. © All rights reserved. Zend Technologies, Inc. How to scale a PHP application? ● The PHP application uses session/local data? ▶ Yes = we have to manage the session/local data across multiple servers ● Using a persistent load balancer ● Share the session data ▶ No = we can scale very easy (stateless) ● Most of the PHP applications are not stateless, they use session data
  • 12. © All rights reserved. Zend Technologies, Inc. Persistent load balancer ● A client request is assigned always to the same server (means same session/local data) ● Pros: ▶ No software architecture changes ● Cons: ▶ No fault tolerant, if a server goes down the session data are lost! ▶ The load balancer is the bottleneck ▶ The persistent load balancer are expensive
  • 13. © All rights reserved. Zend Technologies, Inc. Share the session data ● Manage the session data across the servers ● Pros: ▶ Fault tolerant, if a server goes down the load balancer can user another server ▶ No bottleneck in the load balancer ▶ The stateless load balancer are cheaper ● Cons: ▶ Software architecture changes
  • 14. © All rights reserved. Zend Technologies, Inc. PHP session management
  • 15. © All rights reserved. Zend Technologies, Inc. Sessions in PHP ● Session support in PHP consists of a way to preserve certain data across subsequent accesses ● To identify the subsequent accesses, from the same client, PHP uses a cookie variable (PHPSESSID) ▶ Example: PHPSESSID= tclq3an1ri8dsfiuo43845loo1 ● By default, session data are stored in the file system of the server ● In PHP we manage the session data using the $_SESSION global variable
  • 16. © All rights reserved. Zend Technologies, Inc. PHP session management ● Configure the PHP session management (php.ini directives): ▶ session.name ● name of the session cookie identifier (PHPSESSID by default) ▶ session.save_handler ● defines the name of the handler which is used for storing and retrieving data associated with a session (files by default). ▶ session.save_path ● defines the argument which is passed to the save handler (with files handler is the path to store the session data)
  • 17. © All rights reserved. Zend Technologies, Inc. Example (PHP sessions using files) ● <?php session_start(); $_SESSION['user']= 'enrico'; ● In session folder (for instance, /tmp) the PHP creates a file named sess_fvi9r84f14sjel8r28o6aqspr2 (where fvi9r84f14sjel8r28o6aqspr2 is PHPSESSID) that contains: user|s:6:"enrico";
  • 18. © All rights reserved. Zend Technologies, Inc. Share session data ● How to share PHP sessions between multiple servers? ▶ Using a Network File System ▶ Using a Database ▶ Using Memcached ▶ Using Redis ▶ Using Zend Server Cluster Manager ▶ etc
  • 19. © All rights reserved. Zend Technologies, Inc. session_set_save_handler() ● You can write your PHP session handler using the session_set_save_handler(): bool session_set_save_handler ( callback $open, callback $close, callback $read, callback $write, callback $destroy, callback $gc) ● More info: http://php.net/manual/en/function.session-set-save-handler.php
  • 20. © All rights reserved. Zend Technologies, Inc. Session sharing using NFS
  • 21. © All rights reserved. Zend Technologies, Inc. Session sharing using NFS ● Use the default PHP session handler (session.session_handler= files) ● NFS to store the session data files (session.save_path= NFS folder) ● Pros: ▶ No changes on the PHP side ● Cons: ▶ Highly inefficient ▶ Not designed for high read/write ratio ▶ Performance problems and data corruptions
  • 22. © All rights reserved. Zend Technologies, Inc. Session sharing using Database
  • 23. © All rights reserved. Zend Technologies, Inc. Session sharing using DB ● Use the user PHP session handler (session.session_handler= user) ● Use the session_set_save_handler() to implement your db session handler ● Which db? ▶ MySQL http://www.php.net/manual/en/function.session-set-save-handler.php#81761 ▶ Ms SQL Server ● http://www.zimuel.it/blog/?p=402 ▶ PostgreSQL, Oracle, etc
  • 24. © All rights reserved. Zend Technologies, Inc. Session sharing using DB (2) ● Pros: ▶ Solves the scalability limitation ▶ A lot of best practices available ▶ Wide installation base ▶ DB is (normally) available ● Cons: ▶ Sessions have almost 1:1 read/write ratio ▶ Connection overhead ▶ Single point of failure ▶ Performance bottleneck
  • 25. © All rights reserved. Zend Technologies, Inc. Session sharing using Memcached
  • 26. © All rights reserved. Zend Technologies, Inc. Session sharing using Memcached ● Use the memcached PHP session handler (session.session_handler= memcache) ● Pros: ▶ Native session handler ▶ Very fast (works in RAM) ▶ Can be clustered ● Cons: ▶ No persistent data (it's a caching system) ▶ Cyclic memory (data can be overwritten if the memory is full)
  • 27. © All rights reserved. Zend Technologies, Inc. Session sharing using Redis
  • 28. © All rights reserved. Zend Technologies, Inc. What is Redis? ● Redis is an open-source, networked, in-memory, persistent, journaled, key-value data store (NoSQL). ● It's similar to memcached but the dataset is not volatile ● Developed by: Salvatore Sanfilippo ● Sponsored by vmware ● http://code.google.com/p/redis/
  • 29. © All rights reserved. Zend Technologies, Inc. Session sharing using Redis ● Different PHP extensions for Redis: ▶ Predis, http://github.com/nrk/predis/ ▶ Rediska, http://rediska.geometria-lab.net/ ▶ redis.php, http://github.com/antirez/redisdotphp ▶ PHPRedis!, http://github.com/owlient/phpredis ● Custom session handler for Redis: ▶ http://github.com/ivanstojic/redis-session-php
  • 30. © All rights reserved. Zend Technologies, Inc. Session sharing using Redis (2) ● Pros: ▶ Fast (works in RAM) ▶ Reliable (master-slave replication) ● Cons: ▶ PHP Redis extensions are 0.x version ▶ Custom PHP session handler ▶ Not so scalable* (data are stored in RAM) ▶ No High Availability* (master-slave limitation) * but Redis developers are working on a Cluster version!
  • 31. © All rights reserved. Zend Technologies, Inc. Session sharing using Zend Server Cluster Manager
  • 32. © All rights reserved. Zend Technologies, Inc. What is Zend Server and Cluster Manager? ● Zend Server is a complete, enterprise-ready Web Application Server for running and managing PHP applications that require a high level of reliability, performance and security on Linux, Windows or IBM i. ● Zend Server Cluster Manager (ZSCM) extends the benefits of Zend Server across large-scale PHP deployments. ● With ZSCM you can build a real PHP cluster stack.
  • 33. © All rights reserved. Zend Technologies, Inc. Session sharing with ZSCM ● Session Clustering Extension ● Session Clustering Daemon (SCD) ● Storage backends: Disk / Memory ● Peer-to-peer protocol to communicate between nodes ● Session management with master-backup architecture
  • 34. © All rights reserved. Zend Technologies, Inc. Zend Server Cluster Manager architecture Load Balancer MySQL Firewall
  • 35. © All rights reserved. Zend Technologies, Inc. High availability: session cluster
  • 36. © All rights reserved. Zend Technologies, Inc. High availability: session cluster (2)
  • 37. © All rights reserved. Zend Technologies, Inc. Session cluster with ZSCM ● Pros: ▶ Very Fast ▶ Reliable (data are stored in master-backup servers) ▶ High Availability ▶ Scalable (session data are stored in all the nodes of the cluster) ▶ No changes to the PHP code ● Cons: ▶ You need Zend Server on each node of the cluster
  • 38. © All rights reserved. Zend Technologies, Inc. Questions?
  • 39. © All rights reserved. Zend Technologies, Inc. Thank you for attending! More info: http://www.zend.com http://phpconference.es