SlideShare una empresa de Scribd logo
1 de 18
Webonise Lab
PHP – Session Handling Using
Memcached
PHP – Session

“A method to maintain state of user on Server.”
Session are more like cookies, however there state is maintained
on server. When we start session, session id is stored in cookie
on client side. This session ID inked client to a particular file or
record depending upon how session is started
PHP – Session
Session
Storage

There are multiple ways of handling session in PHP. They are as follows
1. File
2. Relation Database
3. Distributed Caching
FILES

The “Files” session handler in PHP is default session save handler.
It stores session data as files on disk, in a specified directory (or sometimes in
a tree of directories). Usually, this save handler is capable of easily handling
tens of thousands of sessions.

The biggest disadvantage of the files save handler is that it imposes a major
scalability bottleneck when trying to scale an application to run on more than
one server.
Relation
Database

Relation Database is another way to handle session and save it. In this type,
the session and it related data is stored in DB table.
To achieve this, we have to crate a table which will store the session id, host
name and the data.
When ever, client requests for session data, a query will get executed and user
and data will be fetched from database
This way of session handling solves the scalability problem but involved some
major drawback too
Relation
Database

1. Performance
2. Memory
3. Server Failure Handling issue
Memcached

What is Memcached?
–

Memcached (pronounced as ‘mem-cache-D’) is an

open-source

distributed memory based storage system, designed mostly as a fast
caching solution.
–

It is invented by Brad Fitzpatrick
Memcached
Use the following commands for the installations:

Memcached is mainly developed as caching mechanism for distributed sever.
The memcached has proved itself as one of the best caching mechanism in
recent years.
Worlds most highly traffic websites use memcache as there performance
booster. Eg. Facebook
Memcached
Use the following commands for the installations:

The advantages of Memcached are as follows
1. Performance
2. Scalability
3. Easy Installation
Session +
Memcache
Use the following commands for the installations:

Lets see how this equation works for PHP
Session Storage in memcached solves the locality problem, and is usually faster
than most DB session storage implementations.
Memcached is distributed in the sense that data may be spread on multiple
nodes – this makes memcached scalable when it
growing number of concurrent sessions.

comes to handling a
Installation
Installation of memcached is very easy. Follow the following steps to
install memcache in server
STEP #1
sudo apt-get update
sudo apt-get install memcached
Above will install memcached in your linux machine.
Installation
STEP #2 – Installing PHP memcache etension
sudo apt-get install memcahe
OR
sudo apt-get install php5-memcache

Above commands will install memcache extension for PHP. It is available on
PECL
Configurations
Don't open champagne yet. We have to make some configuration in PHP to
have party.
Following are the steps to make configuration
STEP #1
Open your php.ini file and change session save handler. It is by default as
“files”. Change as below
session.save_handler = memcache
STEP #2
Change the session save path
session.save_path = “tcp://hostIP:11211”
Configurations
To handle session using memcache on web cluster (multiserver architecture),
All we need to add another server as comma separated in session save path

session.save_path = “tcp://hostIP:11211, tcp://AnotherHostIP:11211”
In above it is important that both the server should have Memcached installed
and it should allow your server IP to store memcache. To do so we have to
make changes in /etc/memcached.conf file.
Here you will see the “-l 127.0.0.1” as default which mean, only local can save
the memcache. Here you need to add the server IP which you want to allow
FLOW
DONE!
At last we are Done with installation and configuration of PHP. Now its
time to test it

Let's have demo of all the efforts
Thank You!

Más contenido relacionado

La actualidad más candente

Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
elliando dias
 
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusion
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusionAdvanced caching techniques with ehcache, big memory, terracotta, and coldfusion
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusion
ColdFusionConference
 
Distributed Caching Essential Lessons (Ts 1402)
Distributed Caching   Essential Lessons (Ts 1402)Distributed Caching   Essential Lessons (Ts 1402)
Distributed Caching Essential Lessons (Ts 1402)
Yury Kaliaha
 
Tsm7.1 seminar Stavanger
Tsm7.1 seminar StavangerTsm7.1 seminar Stavanger
Tsm7.1 seminar Stavanger
Solv AS
 
Planning & Best Practice for Microsoft Virtualization
Planning & Best Practice for Microsoft VirtualizationPlanning & Best Practice for Microsoft Virtualization
Planning & Best Practice for Microsoft Virtualization
Lai Yoong Seng
 

La actualidad más candente (20)

Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
 
Overview of the ehcache
Overview of the ehcacheOverview of the ehcache
Overview of the ehcache
 
Ehcache Architecture, Features And Usage Patterns
Ehcache Architecture, Features And Usage PatternsEhcache Architecture, Features And Usage Patterns
Ehcache Architecture, Features And Usage Patterns
 
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusion
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusionAdvanced caching techniques with ehcache, big memory, terracotta, and coldfusion
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusion
 
Distributed Caching Essential Lessons (Ts 1402)
Distributed Caching   Essential Lessons (Ts 1402)Distributed Caching   Essential Lessons (Ts 1402)
Distributed Caching Essential Lessons (Ts 1402)
 
Understanding Web Cache
Understanding Web CacheUnderstanding Web Cache
Understanding Web Cache
 
Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetImproving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve Internet
 
5 Reasons to Upgrade Ehcache to BigMemory Go
5 Reasons to Upgrade Ehcache to BigMemory Go5 Reasons to Upgrade Ehcache to BigMemory Go
5 Reasons to Upgrade Ehcache to BigMemory Go
 
World Wide Web Caching
World Wide Web CachingWorld Wide Web Caching
World Wide Web Caching
 
Caching
CachingCaching
Caching
 
Implementing High Availability Caching with Memcached
Implementing High Availability Caching with MemcachedImplementing High Availability Caching with Memcached
Implementing High Availability Caching with Memcached
 
[Hanoi-August 13] Tech Talk on Caching Solutions
[Hanoi-August 13] Tech Talk on Caching Solutions[Hanoi-August 13] Tech Talk on Caching Solutions
[Hanoi-August 13] Tech Talk on Caching Solutions
 
Drupal performance optimization Best Practices
Drupal performance optimization Best PracticesDrupal performance optimization Best Practices
Drupal performance optimization Best Practices
 
Postgres on OpenStack
Postgres on OpenStackPostgres on OpenStack
Postgres on OpenStack
 
Tsm7.1 seminar Stavanger
Tsm7.1 seminar StavangerTsm7.1 seminar Stavanger
Tsm7.1 seminar Stavanger
 
Cassandra as Memcache
Cassandra as MemcacheCassandra as Memcache
Cassandra as Memcache
 
Ehcache3 — JSR-107 on steroids
Ehcache3 — JSR-107 on steroidsEhcache3 — JSR-107 on steroids
Ehcache3 — JSR-107 on steroids
 
Planning & Best Practice for Microsoft Virtualization
Planning & Best Practice for Microsoft VirtualizationPlanning & Best Practice for Microsoft Virtualization
Planning & Best Practice for Microsoft Virtualization
 
MongoDB performance
MongoDB performanceMongoDB performance
MongoDB performance
 
Aioug connection poolsizingconcepts
Aioug connection poolsizingconceptsAioug connection poolsizingconcepts
Aioug connection poolsizingconcepts
 

Similar a Session Handling Using Memcache

Optimizing Magento Performance with Zend Server
Optimizing Magento Performance with Zend ServerOptimizing Magento Performance with Zend Server
Optimizing Magento Performance with Zend Server
varien
 

Similar a Session Handling Using Memcache (20)

phptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorialphptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorial
 
Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011
 
Achieving Massive Scalability and High Availability for PHP Applications in t...
Achieving Massive Scalability and High Availability for PHP Applications in t...Achieving Massive Scalability and High Availability for PHP Applications in t...
Achieving Massive Scalability and High Availability for PHP Applications in t...
 
Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
Drupal7 MEMCACHE
Drupal7 MEMCACHE Drupal7 MEMCACHE
Drupal7 MEMCACHE
 
Give Your Site a Boost with Memcache
Give Your Site a Boost with MemcacheGive Your Site a Boost with Memcache
Give Your Site a Boost with Memcache
 
Caching objects-in-memory
Caching objects-in-memoryCaching objects-in-memory
Caching objects-in-memory
 
Php myadmin
Php myadminPhp myadmin
Php myadmin
 
Optimizing Magento Performance with Zend Server
Optimizing Magento Performance with Zend ServerOptimizing Magento Performance with Zend Server
Optimizing Magento Performance with Zend Server
 
Scaling PHP apps
Scaling PHP appsScaling PHP apps
Scaling PHP apps
 
Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetImproving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve Internet
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
Memcached B box presentation
Memcached B box presentationMemcached B box presentation
Memcached B box presentation
 
Lamp Stack Optimization
Lamp Stack OptimizationLamp Stack Optimization
Lamp Stack Optimization
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
PHP Sessions and Non-Sessions
PHP Sessions and Non-SessionsPHP Sessions and Non-Sessions
PHP Sessions and Non-Sessions
 
Developing High Performance and Scalable ColdFusion Application Using Terraco...
Developing High Performance and Scalable ColdFusion Application Using Terraco...Developing High Performance and Scalable ColdFusion Application Using Terraco...
Developing High Performance and Scalable ColdFusion Application Using Terraco...
 
Developing High Performance and Scalable ColdFusion Applications Using Terrac...
Developing High Performance and Scalable ColdFusion Applications Using Terrac...Developing High Performance and Scalable ColdFusion Applications Using Terrac...
Developing High Performance and Scalable ColdFusion Applications Using Terrac...
 

Último

Último (20)

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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 

Session Handling Using Memcache

  • 1. Webonise Lab PHP – Session Handling Using Memcached
  • 2. PHP – Session “A method to maintain state of user on Server.” Session are more like cookies, however there state is maintained on server. When we start session, session id is stored in cookie on client side. This session ID inked client to a particular file or record depending upon how session is started
  • 4. Session Storage There are multiple ways of handling session in PHP. They are as follows 1. File 2. Relation Database 3. Distributed Caching
  • 5. FILES The “Files” session handler in PHP is default session save handler. It stores session data as files on disk, in a specified directory (or sometimes in a tree of directories). Usually, this save handler is capable of easily handling tens of thousands of sessions. The biggest disadvantage of the files save handler is that it imposes a major scalability bottleneck when trying to scale an application to run on more than one server.
  • 6. Relation Database Relation Database is another way to handle session and save it. In this type, the session and it related data is stored in DB table. To achieve this, we have to crate a table which will store the session id, host name and the data. When ever, client requests for session data, a query will get executed and user and data will be fetched from database This way of session handling solves the scalability problem but involved some major drawback too
  • 7. Relation Database 1. Performance 2. Memory 3. Server Failure Handling issue
  • 8. Memcached What is Memcached? – Memcached (pronounced as ‘mem-cache-D’) is an open-source distributed memory based storage system, designed mostly as a fast caching solution. – It is invented by Brad Fitzpatrick
  • 9. Memcached Use the following commands for the installations: Memcached is mainly developed as caching mechanism for distributed sever. The memcached has proved itself as one of the best caching mechanism in recent years. Worlds most highly traffic websites use memcache as there performance booster. Eg. Facebook
  • 10. Memcached Use the following commands for the installations: The advantages of Memcached are as follows 1. Performance 2. Scalability 3. Easy Installation
  • 11. Session + Memcache Use the following commands for the installations: Lets see how this equation works for PHP Session Storage in memcached solves the locality problem, and is usually faster than most DB session storage implementations. Memcached is distributed in the sense that data may be spread on multiple nodes – this makes memcached scalable when it growing number of concurrent sessions. comes to handling a
  • 12. Installation Installation of memcached is very easy. Follow the following steps to install memcache in server STEP #1 sudo apt-get update sudo apt-get install memcached Above will install memcached in your linux machine.
  • 13. Installation STEP #2 – Installing PHP memcache etension sudo apt-get install memcahe OR sudo apt-get install php5-memcache Above commands will install memcache extension for PHP. It is available on PECL
  • 14. Configurations Don't open champagne yet. We have to make some configuration in PHP to have party. Following are the steps to make configuration STEP #1 Open your php.ini file and change session save handler. It is by default as “files”. Change as below session.save_handler = memcache STEP #2 Change the session save path session.save_path = “tcp://hostIP:11211”
  • 15. Configurations To handle session using memcache on web cluster (multiserver architecture), All we need to add another server as comma separated in session save path session.save_path = “tcp://hostIP:11211, tcp://AnotherHostIP:11211” In above it is important that both the server should have Memcached installed and it should allow your server IP to store memcache. To do so we have to make changes in /etc/memcached.conf file. Here you will see the “-l 127.0.0.1” as default which mean, only local can save the memcache. Here you need to add the server IP which you want to allow
  • 16. FLOW
  • 17. DONE! At last we are Done with installation and configuration of PHP. Now its time to test it Let's have demo of all the efforts