SlideShare a Scribd company logo
Transforming legacy
applications with Symfony2
and Varnish
Transforming legacy PHP applications with Symfony2 and Varnish
Transforming legacy PHP applications with Symfony2 and Varnish
JULY 2012
10 CONCURRENT USERS
~20 SECONDS AVERAGE
HOMEPAGE -> LOGIN -> PERSONAL DETAILS
Why so slow?
PHP4
SQL Server and Windows Server
Sub-optimal caching strategy
Transforming legacy PHP applications with Symfony2 and Varnish
“Rewriting the code from scratch ... (is) the single
worst strategic mistake a software company can
make.”
- Joel Spolsky
“... the quick fix is like quicksand: The clarity of
code goes down and confusion is harvested in its
place.”
- Venkat Subramaniam and Andy Hunt
The Plan
Reduce cost, improve performance
Develop new application framework
Gradual deployment to careerswales.com
API to access shared data
Single sign on and shared sessions
Legacy CMS New Applications
CAREERSWALES.COM
... ENTER SYMFONY2
Why Symfony2?
Used successfully in other projects
Excellent 3rd party libraries
Flexible and easy to extend
Facilitates best practice
PART 1: THE CMS
Catalyst CMS
Cutting edge stack - PHP 5.4, Nginx, FPM
Reusable code through Symfony2 bundles
Inspired by Symfony2 CMF and Sonata
Fraction of the code to maintain
Transforming legacy PHP applications with Symfony2 and Varnish
PART 2: THE API
Take it to the bridge
Bridges MSSQL & MySQL databases
Acts as a facade
Linux + MSSQL = PAIN
Caching with Symfony2 and Doctrine
SQL
Server
API
Application
(Symfony2)
Third parties
MySQL
Website
Application
(Symfony2)
PART 3: SINGLE SIGN ON
Single sign on
Single authentication system for all applications
Uses Central Authentication Service (CAS)
protocol
BeSimpleSsoAuthBundle does heavy lifting
Custom modifications via DI container
PART 4: VARNISH
Varnish
Frontend proxy or HTTP accelerator
Sits between client and server
Shares cached responses between clients
Can perform load balancing and routing
Without Varnish
Client
Client
Client
HTTP://WWW.CAREERSWALES.COM/EN/
Without Varnish
Client
Client
Client
TTL = 1 DAY
TTL = 1 DAY
TTL = 1 DAY
HTTP://WWW.CAREERSWALES.COM/EN/
With Varnish
Client
Client
Client
Varnish
HTTP://WWW.CAREERSWALES.COM/EN/
With Varnish
Client
Client
Client
Varnish
TTL = 1 DAY
TTL = 1 DAY
TTL = 1 DAY
TTL = 1 DAY
HTTP://WWW.CAREERSWALES.COM/EN/
With Varnish
Client
Client
Client
Varnish
Client
Client Client Client
HTTP://WWW.CAREERSWALES.COM/EN/
With Varnish
Client
Client
Client
Varnish
Client
Client Client Client
HTTP://WWW.CAREERSWALES.COM/EN/
ESI Caching
Edge Side Includes
Identifies blocks of HTML which are dynamic
Blocks are independent of the main response
Blocks can be cached and expired individually
Blocks can be identified as public (cacheable) or
private (not cacheable)
TTL = 5 MINS
TTL = 5 DAYS
INVALIDATED
INVALIDATED
INVALIDATED
Carousel Block Caching
Straightforward caching
No personalisation, same for all users
Carousel Block Caching
public function indexAction()
{
$response = new Response();
// cache for 1 minute
$response->setMaxAge(60);
$response->setPublic();
return $this->render(
'BoxUK:Default:index.html.twig',
array(),
$response
);
}
Login Button Caching
More complex: two different states
Can use varying to store two different caches
Use cookies to provide information to Varnish
BUT don’t want to vary on cookie
Login Button Caching
public function indexAction()
{
$response = new Response();
// cache for 1 minute
$response->setMaxAge(60);
$response->setPublic();
$response->setVary('Logged-In');
return $this->render(
'BoxUK:Default:index.html.twig',
array(),
$response
);
}
Login Button Caching
public function onKernelResponse(
FilterResponseEvent $event
)
{
$response = $event->getResponse();
$loggedIn = $this->context->isGranted(
'IS_AUTHENTICATED_FULLY'
) ? 'true' : 'false';
$response
->headers
->set('Logged-In', $loggedIn);
}
Login Button Caching
public function onKernelResponse(
FilterResponseEvent $event
)
{
$response = $event->getResponse();
$cookie = new Cookie('Logged-In',
$loggedIn, ...);
$response
->headers
->setCookie($cookie);
}
Login Button Caching
if (req.http.Cookie ~ 'Logged-In=true') {
set req.http.Logged-In = 'true';
}
Varnish cache keys are hashed on URL (host, path,
etc) and vary data
Symfony takes care of the way out
On the way in, we have to fake the header to
reproduce the hash
Routing
Varnish directs requests to given ‘backends’
Load balancing, e.g. round robin
More complex logic via VCL (Varnish Configuration
Language)
No EC2 load balancers!
Routing
Old
applications
New
applications
10.1.2.1
10.1.2.2
Client Varnish
Examine
request
Defining backends
backend legacy_applications {
.host = "10.1.2.1";
.port = "80";
}
backend new_applications {
.host = "10.1.2.2";
.port = "80";
}
Routing by regex
sub vcl_recv {
! if (req.url ~
"^(.*)www.careerswales.com/old-request-format") {
! set req.backend = legacy_applications;
! return(pipe);
! }
! if (req.url ~
"^(.*)www.careerswales.com/new-request-format") {
! set req.backend = new_applications;
! return(pipe);
! }
}
OLD APPLICATIONS
Client
Varnish
NEW APPLICATIONS
SQL
Server
MySQL
SSO
App
API
APP
www.careerswales.com
/old-request-format
www.careerswales.com
/new-request-format
JULY 2012
10 CONCURRENT USERS
~20 SECONDS AVERAGE
HOMEPAGE -> LOGIN -> PERSONAL DETAILS
JULY 2013
10 CONCURRENT USERS
~4 SECONDS AVERAGE
HOMEPAGE -> LOGIN -> PERSONAL DETAILS
Conclusions
Observable speed increase of 560%No loss of
functionality or downtime
No loss of functionality or downtime
Substantially less ‘hardware’
More complex environment
Transforming legacy PHP applications with Symfony2 and Varnish
Transforming legacy PHP applications with Symfony2 and Varnish
Questions?
@craigmarvelley

More Related Content

PPTX
Modernisation of legacy PHP applications using Symfony2 - PHP Northeast Confe...
PPTX
Integrating Drupal 8 into Symfony 2
PPTX
Symfony2 for legacy app rejuvenation: the eZ Publish case study
PDF
Modernisation of Legacy PHP Applications to Symfony2 - Symfony Live Berlin 2012
PDF
How Drupal 8 Reaches Its Full Potential on Pantheon
PDF
ApacheCon Europe 2016 : CONTAINERS IN ACTION - Transform Application Delivery...
PDF
Intro jbug milano
PDF
Continuous Integration @ MeetMagento Germany 2015
Modernisation of legacy PHP applications using Symfony2 - PHP Northeast Confe...
Integrating Drupal 8 into Symfony 2
Symfony2 for legacy app rejuvenation: the eZ Publish case study
Modernisation of Legacy PHP Applications to Symfony2 - Symfony Live Berlin 2012
How Drupal 8 Reaches Its Full Potential on Pantheon
ApacheCon Europe 2016 : CONTAINERS IN ACTION - Transform Application Delivery...
Intro jbug milano
Continuous Integration @ MeetMagento Germany 2015

Viewers also liked (20)

PPTX
Caching solutions with Varnish
PDF
Preparing code for Php 7 workshop
PDF
PHP 7.1 : elegance of our legacy
PDF
Dealing with Legacy PHP Applications
PDF
Dealing With Legacy PHP Applications
PPTX
Working with Legacy Code
KEY
Working Effectively With Legacy Code
PDF
Working With Legacy Code
PDF
Pimp legacy PHP apps with Apigility - TrueNorthPHP 2014
PPTX
XPDays Ukraine: Legacy
PPTX
XP Days Ukraine 2014 - Refactoring legacy code
PDF
From Legacy to DDD in PHP | Tech Talks | Privalia
PPTX
ITGM#4 Технический долг 2.0
PPTX
Club of anonimous developers "Refactoring: Legacy code"
PPTX
Legacy: как победить в гонке (Joker)
PDF
Living With Legacy Code
PPT
Working Effectively With Legacy Code
PPTX
Clean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
PDF
Refactoring 101
PPTX
Facebook architecture presentation: scalability challenge
Caching solutions with Varnish
Preparing code for Php 7 workshop
PHP 7.1 : elegance of our legacy
Dealing with Legacy PHP Applications
Dealing With Legacy PHP Applications
Working with Legacy Code
Working Effectively With Legacy Code
Working With Legacy Code
Pimp legacy PHP apps with Apigility - TrueNorthPHP 2014
XPDays Ukraine: Legacy
XP Days Ukraine 2014 - Refactoring legacy code
From Legacy to DDD in PHP | Tech Talks | Privalia
ITGM#4 Технический долг 2.0
Club of anonimous developers "Refactoring: Legacy code"
Legacy: как победить в гонке (Joker)
Living With Legacy Code
Working Effectively With Legacy Code
Clean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
Refactoring 101
Facebook architecture presentation: scalability challenge
Ad

Similar to Transforming legacy PHP applications with Symfony2 and Varnish (20)

PPTX
Making Symofny shine with Varnish - SymfonyCon Madrid 2014
PDF
VUG5: Varnish at Opera Software
PDF
Saving The World From Guaranteed APOCALYPSE* Using Varnish and Memcached
PDF
Caching the Uncacheable
PPTX
Varnish & Magento TechTalk @Lyracons
PDF
How we use and deploy Varnish at Opera
PDF
Cache all the things - A guide to caching Drupal
PDF
T3DD12 Caching with Varnish
 
PDF
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
PDF
Speed up your site with Varnish
PPTX
Starting with varnish cache
PDF
Going crazy with Varnish and Symfony
ODP
PHP London Dec 2013 - Varnish - The 9 circles of hell
PDF
PHP Benelux 2017 - Caching The Right Way
PPTX
Varnish intro
PPTX
Иван Чепурный - Meet Magento Ukraine - Varnish Cache and its usage in the rea...
PPTX
Varnish Cache and its usage in the real world!
PDF
High Performance Drupal Sites
PPTX
Improving Performance on Magento 1*
PDF
Symfony live London 2018 - Take your http caching to the next level with xke...
Making Symofny shine with Varnish - SymfonyCon Madrid 2014
VUG5: Varnish at Opera Software
Saving The World From Guaranteed APOCALYPSE* Using Varnish and Memcached
Caching the Uncacheable
Varnish & Magento TechTalk @Lyracons
How we use and deploy Varnish at Opera
Cache all the things - A guide to caching Drupal
T3DD12 Caching with Varnish
 
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Speed up your site with Varnish
Starting with varnish cache
Going crazy with Varnish and Symfony
PHP London Dec 2013 - Varnish - The 9 circles of hell
PHP Benelux 2017 - Caching The Right Way
Varnish intro
Иван Чепурный - Meet Magento Ukraine - Varnish Cache and its usage in the rea...
Varnish Cache and its usage in the real world!
High Performance Drupal Sites
Improving Performance on Magento 1*
Symfony live London 2018 - Take your http caching to the next level with xke...
Ad

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
cuic standard and advanced reporting.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Electronic commerce courselecture one. Pdf
PDF
Encapsulation theory and applications.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Machine learning based COVID-19 study performance prediction
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Cloud computing and distributed systems.
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
20250228 LYD VKU AI Blended-Learning.pptx
Spectroscopy.pptx food analysis technology
Advanced methodologies resolving dimensionality complications for autism neur...
cuic standard and advanced reporting.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Approach and Philosophy of On baking technology
Electronic commerce courselecture one. Pdf
Encapsulation theory and applications.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Machine learning based COVID-19 study performance prediction
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
“AI and Expert System Decision Support & Business Intelligence Systems”
Encapsulation_ Review paper, used for researhc scholars
sap open course for s4hana steps from ECC to s4
Empathic Computing: Creating Shared Understanding
Cloud computing and distributed systems.

Transforming legacy PHP applications with Symfony2 and Varnish