The document discusses using Varnish as a cache accelerator in front of Symfony applications. It provides an overview of Varnish configuration using VCL, the request flow through Varnish, and new features in Varnish 4. It also covers specific techniques for caching Symfony applications, including normalizing URLs and cookies, load balancing backends, handling internationalization, and invalidating caches.
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...Alexander Lisachenko
It is believed that the Symfony framework is quite heavy and it can be difficult to develop a website that will be able to work under the high load. It is true, but does this mean that it is impossible to implement a dynamic caching and to update only a small part of entire page as data is updated? This talk will give your an answer to that. It is Varnish, ESI-blocks and load balancing. With hundreds of thousands of unique visitors and million hits a day, we continue to use Symfony, and do not see any problems.
You know how HTTP caching works but need more? In this talk we look into ways to cache personalized content. We will look at Edge Side Includes (ESI) to tailor caching rules of fragments, and at the user context concept to differentiate caches not by individual user but by permission groups.
Puppet is a configuration management tool which allows easy deployment and configuration ranging from 1 to 1 thousand servers (and even more). Even though its common knowledge for devops, puppet is still a strange piece of software for developers. How does it work and what can it do for you as a developer?
PECL Picks - Extensions to make your life betterZendCon
One of the biggest strengths of PHP is its "glue" power. Take any C library and with a little magic and a compiler you have a fantastic extension. These extensions hide in PECL, but few people can tell the good from the unmaintained or just plain broken. Find the best extensions for your project, learn about PECL, and find out how to become a part of the PECL developer community.
Ansible: How to Get More Sleep and Require Less CoffeeSarah Z
Why you need automation, configuration management and remote execution in your life. An intro to Ansible and how it can make your life in Ops infinitely easier.
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...Alexander Lisachenko
It is believed that the Symfony framework is quite heavy and it can be difficult to develop a website that will be able to work under the high load. It is true, but does this mean that it is impossible to implement a dynamic caching and to update only a small part of entire page as data is updated? This talk will give your an answer to that. It is Varnish, ESI-blocks and load balancing. With hundreds of thousands of unique visitors and million hits a day, we continue to use Symfony, and do not see any problems.
You know how HTTP caching works but need more? In this talk we look into ways to cache personalized content. We will look at Edge Side Includes (ESI) to tailor caching rules of fragments, and at the user context concept to differentiate caches not by individual user but by permission groups.
Puppet is a configuration management tool which allows easy deployment and configuration ranging from 1 to 1 thousand servers (and even more). Even though its common knowledge for devops, puppet is still a strange piece of software for developers. How does it work and what can it do for you as a developer?
PECL Picks - Extensions to make your life betterZendCon
One of the biggest strengths of PHP is its "glue" power. Take any C library and with a little magic and a compiler you have a fantastic extension. These extensions hide in PECL, but few people can tell the good from the unmaintained or just plain broken. Find the best extensions for your project, learn about PECL, and find out how to become a part of the PECL developer community.
Ansible: How to Get More Sleep and Require Less CoffeeSarah Z
Why you need automation, configuration management and remote execution in your life. An intro to Ansible and how it can make your life in Ops infinitely easier.
Why work with Ansible to deliver software in a secure and reliable way? Gain insight quickly, this deck shows the strenghts of the IT automation tool that does it all.
Bas Meijer is an Ansible Ambassador co-hosting the Ansible Benelux Meetup since 2014. He introduced the tool to major corporate clients for use in mission critical infrastructure provisioning, application construction, container orchestration, security operations, and more.
EC2 AMI Factory with Chef, Berkshelf, and PackerGeorge Miranda
Presentation accompanying a Live Demo at the AWS Pop-Up Loft in San Francisco on using Chef + Berks + Packer to create an AWS EC2 AMI Factory.
Demo Repo available here -- https://github.com/gmiranda23/chef-ami-factory
Create Development and Production Environments with VagrantBrian Hogan
Need a Linux box to test a Wordpress site or a Windows VM to test a web site on IE 10? Creating a virtual machine to test or deploy your software doesn’t have to be a manual process. Bring one up in seconds with Vagrant, software for creating and managing virtual machines. With Vagrant, you can bring up a new virtual machine with the software you need, share directories, copy files, and configure networking using a friendly DSL. You can even use shell scripts or more powerful provisioning tools to set up your software and install your apps. Whether you need a Windows machine for testing an app, or a full-blown production environment for your apps, Vagrant has you covered.
In this talk you’ll learn to script the creation of multiple local virtual machines. Then you’ll use the same strategy to provision production servers in the cloud.
I work with Vagrant, Terraform, Docker, and other provisioning systems daily and am excited to show others how to bring this into their own workflows.
Plack basics for Perl websites - YAPC::EU 2011leo lapworth
Run a website with Perl? - you should learn how to use Plack. Most Perl web frameworks support it and it makes your life a lot easier and a lot more fun
Cooking Perl with Chef: Real World Tutorial with JitterbugDavid Golden
This tutorial provides a command-by-command walk-through for deploying the Jitterbug continuous integration application using the Chef configuration management tool
Can you contain the future - Docker, Container Technologies, The Future, and YouColdFusionConference
Linux containers and Docker have been all the rage in sysOps for quite some time now. Come to this session to learn about how you can or if you should be using them, and to learn about container technologies, how thy differ from VMs and if they truly are the future. Take a look at Docker basics and get an understanding of how it can be used as part of your workflow, not just for development, but for production deployments as well. We will also bust some Myths surrounding container technologies and Docker.
Creating and Deploying Static Sites with HugoBrian Hogan
Most web sites don’t have data that changes, so why power them with a database and take the performance hit? In this talk we’ll explore static site generation using Hugo, an open-source static site generator. You’ll learn how to make a master layout for all pages, and how to use Markdown to create your content pages quickly.
Then we’ll explore how to deploy the site we made to production. We’ll automate the entire process. When you’re done, you’ll be able to build and deploy static web sites quickly with minimal tooling.
Vagrant is a well-known tool for creating development environments in a simple and consistent way. Since we adopted in our organization we experienced several benefits: lower project setup times, better shared knowledge among team members, less wtf moments ;-)
In this session I'd like to share our experience, including but not limited to:
- advanced vagrantfile configuration
- vm configuration tips for dev environment: performance, debug, tuning
- our wtf moments
- puphet/phansilbe: hot or not?
- tips for sharing a box
CIRCUIT 2015 - AEM Infrastructure Automation with Chef CookbooksICF CIRCUIT
Drew Glass - Hero Digital
Push button deployments can automate AEM infrastructure to reduce costs and defects. Chef is a platform that enables this by transforming infrastructure into code using DevOps practices. AEM Author, Publish and Dispatcher instances can be fully configured and deployed as code with Chef. In this talk we will discuss how the open source AEM Chef Cookbook can be used to automate the deployment of AEM instances with Chef features like recipes, attributes, providers and resources. Out of the box, the AEM Chef Cookbook supports:
- Unattended installation of AEM Author, Publish, and Dispatcher nodes.
- Automatic search for and configuration of AEM cluster members using Chef searches.
- Configuration for replication agents using the replicator provider.
- Configurations for Dispatcher farms with the farm provider.
- Deploying and removing AEM packages with the package provider.
We will also discuss how AEM can be automated to supported different SSO and deployment scenarios like cold standby. Finally, we will cover how to extend the Cookbook to support your project specific needs.
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011Alessandro Nadalin
In the first part of the presentation we see how Symfony2 implements HTTP cache.
In the second one there's an explanation of why application cache layers suck, why nerly every php application does caching in the less productive way and how you benefit from HTTP cache from this point of view.
Why work with Ansible to deliver software in a secure and reliable way? Gain insight quickly, this deck shows the strenghts of the IT automation tool that does it all.
Bas Meijer is an Ansible Ambassador co-hosting the Ansible Benelux Meetup since 2014. He introduced the tool to major corporate clients for use in mission critical infrastructure provisioning, application construction, container orchestration, security operations, and more.
EC2 AMI Factory with Chef, Berkshelf, and PackerGeorge Miranda
Presentation accompanying a Live Demo at the AWS Pop-Up Loft in San Francisco on using Chef + Berks + Packer to create an AWS EC2 AMI Factory.
Demo Repo available here -- https://github.com/gmiranda23/chef-ami-factory
Create Development and Production Environments with VagrantBrian Hogan
Need a Linux box to test a Wordpress site or a Windows VM to test a web site on IE 10? Creating a virtual machine to test or deploy your software doesn’t have to be a manual process. Bring one up in seconds with Vagrant, software for creating and managing virtual machines. With Vagrant, you can bring up a new virtual machine with the software you need, share directories, copy files, and configure networking using a friendly DSL. You can even use shell scripts or more powerful provisioning tools to set up your software and install your apps. Whether you need a Windows machine for testing an app, or a full-blown production environment for your apps, Vagrant has you covered.
In this talk you’ll learn to script the creation of multiple local virtual machines. Then you’ll use the same strategy to provision production servers in the cloud.
I work with Vagrant, Terraform, Docker, and other provisioning systems daily and am excited to show others how to bring this into their own workflows.
Plack basics for Perl websites - YAPC::EU 2011leo lapworth
Run a website with Perl? - you should learn how to use Plack. Most Perl web frameworks support it and it makes your life a lot easier and a lot more fun
Cooking Perl with Chef: Real World Tutorial with JitterbugDavid Golden
This tutorial provides a command-by-command walk-through for deploying the Jitterbug continuous integration application using the Chef configuration management tool
Can you contain the future - Docker, Container Technologies, The Future, and YouColdFusionConference
Linux containers and Docker have been all the rage in sysOps for quite some time now. Come to this session to learn about how you can or if you should be using them, and to learn about container technologies, how thy differ from VMs and if they truly are the future. Take a look at Docker basics and get an understanding of how it can be used as part of your workflow, not just for development, but for production deployments as well. We will also bust some Myths surrounding container technologies and Docker.
Creating and Deploying Static Sites with HugoBrian Hogan
Most web sites don’t have data that changes, so why power them with a database and take the performance hit? In this talk we’ll explore static site generation using Hugo, an open-source static site generator. You’ll learn how to make a master layout for all pages, and how to use Markdown to create your content pages quickly.
Then we’ll explore how to deploy the site we made to production. We’ll automate the entire process. When you’re done, you’ll be able to build and deploy static web sites quickly with minimal tooling.
Vagrant is a well-known tool for creating development environments in a simple and consistent way. Since we adopted in our organization we experienced several benefits: lower project setup times, better shared knowledge among team members, less wtf moments ;-)
In this session I'd like to share our experience, including but not limited to:
- advanced vagrantfile configuration
- vm configuration tips for dev environment: performance, debug, tuning
- our wtf moments
- puphet/phansilbe: hot or not?
- tips for sharing a box
CIRCUIT 2015 - AEM Infrastructure Automation with Chef CookbooksICF CIRCUIT
Drew Glass - Hero Digital
Push button deployments can automate AEM infrastructure to reduce costs and defects. Chef is a platform that enables this by transforming infrastructure into code using DevOps practices. AEM Author, Publish and Dispatcher instances can be fully configured and deployed as code with Chef. In this talk we will discuss how the open source AEM Chef Cookbook can be used to automate the deployment of AEM instances with Chef features like recipes, attributes, providers and resources. Out of the box, the AEM Chef Cookbook supports:
- Unattended installation of AEM Author, Publish, and Dispatcher nodes.
- Automatic search for and configuration of AEM cluster members using Chef searches.
- Configuration for replication agents using the replicator provider.
- Configurations for Dispatcher farms with the farm provider.
- Deploying and removing AEM packages with the package provider.
We will also discuss how AEM can be automated to supported different SSO and deployment scenarios like cold standby. Finally, we will cover how to extend the Cookbook to support your project specific needs.
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011Alessandro Nadalin
In the first part of the presentation we see how Symfony2 implements HTTP cache.
In the second one there's an explanation of why application cache layers suck, why nerly every php application does caching in the less productive way and how you benefit from HTTP cache from this point of view.
A brief run through of the various APIs Google offers for creating free interactive and static data visualizations.
Links mentioned in this presentation: http://dev.kingkool68.com/google-charting-api/list-o-links.html
Effective Doctrine2: Performance Tips for Symfony2 DevelopersMarcin Chwedziak
How to boost performance Doctrine2 with Symfony2. How to configure metadata caching? How to optimize DQL queries for caching. How to properly setup transaction demarcation with EntityManager. How to deal with EntityManager and Listeners with Symfony2 container.
Rationally boost your symfony2 application with caching tips and monitoringGiulio De Donato
Turin SymfonyDay, 5th October 2012 by @liuggio - I will try to keep the tips updated, I suggest you put this talk to your favorites. - Any comment or feedback are really appreciated.
Speed up your Symfony2 application and build awesome features with RedisRicard Clau
Redis is an extremely fast data structure server that can be easily added to your existing stack and act like a Swiss army knife to help solve many problems that would be extremely difficult to workaround with the traditional RDBMS. In this session we will focus on what Redis is, how it works, what awesome features we can build with it and how we can use it with PHP and integrate it with Symfony2 applications making them blazing fast.
You have amazing content and you want to get it to your users as fast as possible. In today’s industry, milliseconds matter and slow websites will never keep up. You can use a CDN but they are expensive, make you dependent on a third party to deliver your content, and can be notoriously inflexible. Enter Varnish, a powerful, open-source caching reverse proxy that lives in your network and lets you take control of how your content is managed and delivered. We’ll discuss how to install and configure Varnish in front of a typical web application, how to handle sessions and security, and how you can customize Varnish to your unique needs. This session will teach you how Varnish can help you give your users a better experience while saving your company and clients money at the same time.
Slide for a talk I presented internally at Opera in December 2009 about the deployment of varnish in our production environment at my.opera.com, the social network community.
Today's high-traffic web sites must implement performance-boosting measures that reduce data processing and reduce load on the database, while increasing the speed of content delivery. One such method is the use of a cache to temporarily store whole pages, database recordsets, large objects, and sessions. While many caching mechanisms exist, memcached provides one of the fastest and easiest-to-use caching servers. Coupling memcached with the alternative PHP cache (APC) can greatly improve performance by reducing data processing time. In this talk, Ben Ramsey covers memcached and the pecl/memcached and pecl/apc extensions for PHP, exploring caching strategies, a variety of configuration options to fine-tune your caching solution, and discusses when it may be appropriate to use memcached vs. APC to cache objects or data.
How we use Varnish at Opera Software, from the beginning (2009) to now.
Presentation hold for the 5th Varnish Users Group meeting (VUG5) held in Paris on March 22nd 2012.
Learn from Fastly veteran Cassandra Dixon on some of the most common customer issues we see — such as why things aren’t caching, misconfigured origins, issues with intermediary proxies, and VCL snafus — and the best ways to resolve them. We’ll also discuss our unique approach to debugging — using seemingly mundane tools to diagnose issues in creative ways — and how you can apply these methods to your own organization to get the most out of Fastly’s offerings.
In this talk, we'll cover all the great built-in rails caching options and best practices for getting the most out of these. Then we'll talk about dynamic content, why it's traditionally not cached, and how you can can cache it using this thing called "edge caching".
Welcome to the future, where you can cache the uncacheable.
Next Generation DevOps in Drupal: DrupalCamp London 2014Barney Hanlon
In this talk, Barney will be discussing and demonstrating how to:
- Use nginx, Varnish and Apache together in a "SPDY sandwich" to support HTTP 2.0
- Setting up SSL properly to mitigate against attack vectors
- Performance improvements with mod_pagespeed and nginx
- Deploying Drupal sites with Docker containers
Barney is a Technical Team Leader at Inviqa, a Drupal Association member and writes for Techportal on using technologies to improve website performance. He first started using PHP professionally in 2003, and has over seventeen years experience in software development. He is an advocate of Scrum methodology and has an interest in performance optimization, researching and speaking on various techniques to improve user experience through faster load times.
A presentation I gave on September 26 at the Melbourne Symfony developers group on using Environment Variables (envvars) in Symfony and managing secrets in your PHP applications.
For more information on these subjects, check out the supporting piece I wrote: https://samjarrett.com.au/swipe-right
When it comes to caching, there are two types of web developers - those with phat stacks of cache money and those suffering from cache anxiety. Caching is particularly handy when scaling Rails apps, however we often avoid putting in effort because it can quickly get complicated without effective strategies. Rails provides a host of built-in caching interfaces that are easy to leverage and extend. I’ll talk about how to do this and combine rails with technologies like CDNs and HTTP accelerators like Varnish so that you can more effectively cache everything, everywhere without fear of serving stale content.
Michael May is an API Engineer at Fastly and a former Austinite, now hailing from San Francisco. While in Texas he studied at UT Austin and co-founded CDN Sumo, which was acquired by Fastly. He’s waiting for the day when FaaS (Franklin BBQ as a Service) becomes a thing and dreams about fast websites.
PHPCR e API Platform: cosa significa davvero sviluppare un CMF con SymfonyInnoteam Srl
Scrivere un CMF da zero: uno degli strumenti che il mondo PHP/Symfony mette a disposizione per la gestione dei contenuti è PHPCR. Nelle slide di questo talk presentato al SymfonyDay 2018 spieghiamo come abbiamo utilizzato Doctrine PHPCR ODM e API Platform per poter costruire un CMF ed esporre le sue funzionalità in maniera REST. Inoltre mostriamo gli imprevisti che ci ha lasciato e come li abbiamo superati.
Similar to Making Symofny shine with Varnish - SymfonyCon Madrid 2014 (20)
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC
Ellisha Heppner, Grant Management Lead, presented an update on APNIC Foundation to the PNG DNS Forum held from 6 to 10 May, 2024 in Port Moresby, Papua New Guinea.
Understanding User Behavior with Google Analytics.pdfSEO Article Boost
Unlocking the full potential of Google Analytics is crucial for understanding and optimizing your website’s performance. This guide dives deep into the essential aspects of Google Analytics, from analyzing traffic sources to understanding user demographics and tracking user engagement.
Traffic Sources Analysis:
Discover where your website traffic originates. By examining the Acquisition section, you can identify whether visitors come from organic search, paid campaigns, direct visits, social media, or referral links. This knowledge helps in refining marketing strategies and optimizing resource allocation.
User Demographics Insights:
Gain a comprehensive view of your audience by exploring demographic data in the Audience section. Understand age, gender, and interests to tailor your marketing strategies effectively. Leverage this information to create personalized content and improve user engagement and conversion rates.
Tracking User Engagement:
Learn how to measure user interaction with your site through key metrics like bounce rate, average session duration, and pages per session. Enhance user experience by analyzing engagement metrics and implementing strategies to keep visitors engaged.
Conversion Rate Optimization:
Understand the importance of conversion rates and how to track them using Google Analytics. Set up Goals, analyze conversion funnels, segment your audience, and employ A/B testing to optimize your website for higher conversions. Utilize ecommerce tracking and multi-channel funnels for a detailed view of your sales performance and marketing channel contributions.
Custom Reports and Dashboards:
Create custom reports and dashboards to visualize and interpret data relevant to your business goals. Use advanced filters, segments, and visualization options to gain deeper insights. Incorporate custom dimensions and metrics for tailored data analysis. Integrate external data sources to enrich your analytics and make well-informed decisions.
This guide is designed to help you harness the power of Google Analytics for making data-driven decisions that enhance website performance and achieve your digital marketing objectives. Whether you are looking to improve SEO, refine your social media strategy, or boost conversion rates, understanding and utilizing Google Analytics is essential for your success.
Italy Agriculture Equipment Market Outlook to 2027harveenkaur52
Agriculture and Animal Care
Ken Research has an expertise in Agriculture and Animal Care sector and offer vast collection of information related to all major aspects such as Agriculture equipment, Crop Protection, Seed, Agriculture Chemical, Fertilizers, Protected Cultivators, Palm Oil, Hybrid Seed, Animal Feed additives and many more.
Our continuous study and findings in agriculture sector provide better insights to companies dealing with related product and services, government and agriculture associations, researchers and students to well understand the present and expected scenario.
Our Animal care category provides solutions on Animal Healthcare and related products and services, including, animal feed additives, vaccination
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdfFlorence Consulting
Quattordicesimo Meetup di Milano, tenutosi a Milano il 23 Maggio 2024 dalle ore 17:00 alle ore 18:30 in presenza e da remoto.
Abbiamo parlato di come Axpo Italia S.p.A. ha ridotto il technical debt migrando le proprie APIs da Mule 3.9 a Mule 4.4 passando anche da on-premises a CloudHub 1.0.
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBrad Spiegel Macon GA
Brad Spiegel Macon GA’s journey exemplifies the profound impact that one individual can have on their community. Through his unwavering dedication to digital inclusion, he’s not only bridging the gap in Macon but also setting an example for others to follow.
4. Making Symfony shine with Varnish
Do we need a cache accelerator?
• Symfony is FAST considering all the features it provides
• See my talk in last year’s deSymfony conference in Madrid (in
Spanish):
http://www.desymfony.com/ponencia/2013/porque-symfony2-
es-rapido
6. Making Symfony shine with Varnish
Our case: clippingbook.com
• We were able to handle 100 req/sec
• But this was not enough to handle our load, specially when
doing Facebook promotions
• We chose Symfony because of its lower costs of development
and manteinance, not for its performance
• We do not want to renounce to any Symfony features (ORM,
Twig templates, ...)
• We could have scaled vertically or horizontally but chose to
implement a caching strategy first
7. Making Symfony shine with Varnish
The solution: Varnish
• The solution: install Varnish Cache
• Varnish Cache is a web application accelerator also known as a
caching HTTP reverse proxy
• It sits in front of your HTTP server and caches its responses,
serving content from the cache whenever possible.
• Result: we can now serve 10000 req/sec, a 100x improvement
8. Making Symfony shine with Varnish
What we will not cover
• How HTTP caching works. For more information see:
http://tools.ietf.org/pdf/rfc2616.pdf (HTTP 1.1 specification, see
section 13 for caching)
http://symfony.com/doc/current/book/http_cache.html (HTTP
caching chapter in the Symfony Book)
• Basic Varnish installation and configuration. See Fabien’s talk:
http://www.desymfony.com/ponencia/2012/varnish
9. Making Symfony shine with Varnish
What we will cover
• Why Varnish
• Quick overview of Varnish configuration
• Varnish 4. What’s new
• Using Varnish with Symfony:
• Backends
• URL normalization
• Cookies and sessions
• Internacionalization
• Serving content for different devices
• Defining caching headers
• Cache invalidation
• Cache validation
• Edge Side Includes (ESI)
10. Making Symfony shine with Varnish
Why Varnish?
PROs
• Varnish is really fast and highly configurable
• It is well documented in the Symfony documentation
• There are some bundles which help you interact with it
• Fabien’s talk provided very good information on how to use it
CONs
• Varnish documentation not too good / VCL can be cryptic
• It does not handle SSL
• Only runs on 64 bit machines
11. Making Symfony shine with Varnish
Varnish configuration overview
• Varnish uses VCL, a DSL similar to C or Perl
• Configuration saved to a file, usually /etc/varnish/default.vcl
• Translated into C, compiled and linked => fast
• Uses a number of subroutines which are called at specific times
during the handling of the request. For example vcl_recv
• These functions return a value which defines the next action that
the system will take. For example fetch
• There is a default VCL code for each function which is executed if
no value is returned
• We have some objects which represent the request (req), the
response (resp), the backend request (bereq), the backend
response (beresp) and the object in the cache (obj)
sub vcl_miss {
return (fetch);
}
13. Making Symfony shine with Varnish
Request flow
• A request is received (vcl_recv) and we decide if we want to look it
up in the cache (hash) or not (pass)
• If we do not look it up in the cache (vcl_pass) we fetch the
response from the backend (fetch) and don´t store it in the cache
• If we want to look it up, we create a hash for the content
(vcl_hash) and then look it up (lookup)
• If we find it in the cache (vcl_hit) we deliver it (deliver)
• If we don’t find it in the cache (vcl_miss) we fetch the response
from the backend (fetch)
• If we need to fetch the content, we build a request for the backend
and send it (vcl_backend_fetch)
• We receive a response from the back end (vcl_backend_response),
decide if we want to cache it and deliver it (deliver)
• We finally deliver the response to the client (vcl_deliver)
14. Making Symfony shine with Varnish
Varnish 4: what’s new
• Different threads are used for serving client requests and
backend requests
• This split allows Varnish to refresh content in the background
while serving stale content quickly to the client.
• Varnish now correctly handles cache validation, sending If-
None-Match and If-Modified-Since headers and processing
Etag and Last-Modified headers
15. Making Symfony shine with Varnish
Varnish 4: what’s changed
• req.request is now req.method (for example POST)
• vcl_fetch is now vcl_backend_response
• We have a new vcl_backend_fetch function
• To mark responses as uncacheable (hit for pass) we now use
beresp.uncacheable = true
• The purge function is no longer available. You purge content by
returning purge from vcl_recv
• vcl_recv must now return hash instead of lookup
• vcl_hash must now return lookup instead of hash
• vcl_pass must now return fetch instead of pass
• Backend restart is now retry
• Logging tools like varnishlog now have a new filtering language
which means their syntax has changed (-m option => -q)
16. Making Symfony shine with Varnish
Load balancing: backends
backend back1 {
.host = "back1.clippingbook.com";
.port = "80";
}
backend back2 {
.host = "back2.clippingbook.com";
.port = "80";
}
sub vcl_init {
new backs = directors.hash();
backs.add_backend(back1,1);
backs.add_backend(back2,1);
}
sub vcl_recv {
set req.backend_hint = backs.backend(client.identity);
}
17. Making Symfony shine with Varnish
Load balancing: backends
• Varnish includes a health check mechanism and can exclude
backends which are not healthy
• There are other load balancing mechanisms: random, round-robin,
url-based (or build your own)
• BUT if you are using the standard file-based session save
mechanism of Symfony the only method safe to use is hash
based on client ip or client session cookie
• Even this can lead to problems if one server turns unhealthy
and Varnish has to redirect to another backend
• Our recommendation: switch to a shared session server using a
database (PdoSessionHandler), Memcached
(MemcachedSessionHandler) or Redis (ScnRedisBundle)
18. Making Symfony shine with Varnish
URL normalization
• In vcl_hash we calculate a hash to look up the content in the
cache. By default it uses the URL + the host (or IP)
• We want to normalize this URL/host in order to avoid having
repeated content in the cache
• Convert the host to lowercase using std.tolower
• Remove www from the host if present
• Normalize all the query parameters using std.querysort
• Use RouterUnslashBundle to redirect all URLs to the version not
ending in /
• Note that this hash does not include Vary content
sub vcl_hash {
set req.http.host = std.tolower(req.http.host);
set req.http.host = regsub(req.http.host, "^www.", "");
set req.url = std.querysort(req.url);
}
19. Making Symfony shine with Varnish
Cookies and sessions
• Varnish by default will not cache anything which has a cookie
• Symfony sets a PHPSESSID cookie in almost all responses
• By default no content will be cached!
• We want to pass the PHPSESSID cookie to the backend but still
cache some pages even if it is set
• We must not cache any page where this cookie produces a
different response: logged users, forms (CSRF), flashes
• We do not want to cache any page for logged in users
• Most cookies are used by the client side and can be ignored
• There are some cookies which produce a different response but
it is the same for all users => we can Vary on them
• We want to clear all cookies for static content
20. Making Symfony shine with Varnish
Cookies and sessions
sub vcl_recv {
set req.http.X-cookie = req.http.cookie;
if (!req.http.Cookie ~ "Logged-In") {
unset req.http.Cookie;
}
if (req.url ~ ".(png|gif|jpg|css|js|html)$") {
unset req.http.cookie;
}
}
sub vcl_hash {
set req.http.cookie = req.http.X-cookie;
if (req.http.cookie ~ "hide_newsletter=") {
set req.http.X-Newsletter = 1;
}
}
sub vcl_pass {
set req.http.cookie = req.http.X-cookie;
}
21. Making Symfony shine with Varnish
Cookies and sessions
sub vcl_backend_response {
if (!beresp.http.Vary) {
set beresp.http.Vary = "X-Newsletter";
} elseif (beresp.http.Vary !~ "X-Newsletter") {
set beresp.http.Vary = beresp.http.Vary + ", X-Newsletter";
}
if (bereq.url ~ ".(png|gif|jpg|css|js|html)$") {
unset beresp.http.set-cookie;
}
}
sub vcl_deliver {
set resp.http.Vary = regsub(resp.http.Vary, "X-Newsletter",
"Cookie");
}
22. Making Symfony shine with Varnish
Cookies and sessions
• To create the Logged-In cookie we define a kernel.response
listener, injecting the security.context and adding/removing
the cookie as needed
23. Making Symfony shine with Varnish
Cookies and sessions
public function onKernelResponse (FilterResponseEvent $event)
{
$response = $event->getResponse();
$request = $event->getRequest();
if ($this->context->getToken() && $this->context-
>isGranted('IS_AUTHENTICATED_FULLY')) {
if (!$request->cookies->has('Logged-In')) {
$cookie = new Cookie ('Logged-In','true');
$response->headers->setCookie($cookie);
}
} else {
if ($request->cookies->has('Logged-In')) {
$response->headers->clearCookie('Logged-In');
}
}
}
24. Making Symfony shine with Varnish
Internacionalization
• If you return different content depending on a header, use the
Vary header. A common case is returning different content
based on the Accept-Language header
• But you should normalize it or your cache won’t be efficient
if (req.http.Accept-Language) {
if (req.http.Accept-Language ~ "en") {
set req.http.Accept-Language = "en";
} elsif (req.http.Accept-Language ~ "es") {
set req.http.Accept-Language = "es";
} else {
unset req.http.Accept-Language
}
}
• This is a bit simplistic. Use
https://github.com/cosimo/varnish-accept-language
• Varnish will automatically take care of Accept-Encoding
25. Making Symfony shine with Varnish
Device detection
• Another case may be device detection. We want to normalize
the user-agent and Vary on it. We can use
https://github.com/varnish/varnish-devicedetect
include "devicedetect.vcl";
sub vcl_recv { call devicedetect; } #sets X-UA-Device header
sub vcl_backend_response {
if (!beresp.http.Vary) {
set beresp.http.Vary = "X-UA-Device";
} elseif (beresp.http.Vary !~ "X-UA-Device") {
set beresp.http.Vary = beresp.http.Vary + ", X-UA-Device";
}
}
sub vcl_deliver {
set resp.http.Vary = regsub(resp.http.Vary, "X-UA-Device",
"User-Agent");
}
26. Making Symfony shine with Varnish
Device detection
• We can copy this X-UA-Device header to the user-agent
header (but we are losing information)
sub vcl_backend_fetch {
set bereq.http.user-agent = bereq.http.X-UA-Device;
}
• Else we can use the X-UA-Device directly. If, for example, we
use LiipThemeBundle, we can configure it:
liip_theme:
autodetect_theme: acme.device.detector
• acme.device.director is a service which implements the
LiipThemeBundleHelperDeviceDetectionInterface
interface and which uses X-UA-Device to choose a theme
27. Making Symfony shine with Varnish
Defining caching headers
• Set them directly in the Response object
$response->setSharedMaxAge(600);
$response->setPublic();
$response->setVary('Accept-Language');
• Use SensioFrameworkExtraBundle and the @Cache annotation
use SensioBundleFrameworkExtraBundleConfigurationCache;
/**
* @Cache(smaxage="600")
* @Cache(public=true)
* @Cache(vary={"Accept-Language"})
*/
28. Making Symfony shine with Varnish
Defining caching headers
• Use FOSHttpCacheBundle to set them in your config file
fos_http_cache:
cache_control:
rules:
-
match:
attributes: {route: ^book_list$ }
headers:
cache_control: { public: true, s_maxage: 600 }
-
match:
path: ^/info/*$
headers:
cache_control: { public: true, s_maxage: 3600 }
vary: Accept-Language
29. Making Symfony shine with Varnish
Cache invalidation
• First use case: update pages when you deploy new code
• If it is a minor and non-BC breaking change, just wait for the
cache expiration headers to do their job.
• You may need to use some cache busting mechanism like the
assets_version parameter for cache validation
• If it is a major or BC-breaking change, we just bite the bullet and
clear the whole cache by restarting Varnish
service varnish restart
• Downtime is almost inexistent but you will lose all your cached
content
• If this is important, you may want to build a cache warmer
which preloads all your important urls into the cache
30. Making Symfony shine with Varnish
Cache invalidation
• Second use case: a more granular approach: invalidate
individual pages when the underlying data changes
• We can use FOSHttpCacheBundle. First configure Varnish:
acl invalidators {
"back1.clippingbook.com";
"back2.clippingbook.com";
}
sub vcl_recv {
if (req.method == "PURGE") {
if (!client.ip ~ invalidators) {
return (synth(405, "Not allowed"));
}
return (purge);
}
if (req.http.Cache-Control ~ "no-cache" && client.ip ~
invalidators) {
set req.hash_always_miss = true;
}
}
31. Making Symfony shine with Varnish
Cache invalidation
• We then need to configure a Varnish server in Symfony:
fos_http_cache:
proxy_client:
varnish:
servers: xxx.xxx.xxx.xxx #IP of Varnish server
base_url: clippingbook.com
• We can now invalidate or refresh content programatically
$cacheManager = $container ->
get('fos_http_cache.cache_manager');
$cacheManager->invalidatePath('/books');
$cacheManager->refreshRoute('book_show', array('id' =>
$bookId));
$cacheManager->flush(); //optional
32. Making Symfony shine with Varnish
Cache invalidation
• We can also use annotations:
use FOSHttpCacheBundleConfigurationInvalidatePath;
/**
* @InvalidatePath("/books")
* @InvalidateRoute("book_show", params={"id" =
{"expression"="id"}})")
*/
public function editBookAction($id)
{
}
• This needs that SensioFrameworkExtraBundle is available and, if
we use expressions, that the ExpressionLanguage component is
installed
33. Making Symfony shine with Varnish
Cache invalidation
• Finally, we can set up invalidation in our config file:
fos_http_cache:
invalidation:
rules:
-
match:
attributes:
_route: "book_edit|book_delete"
routes:
book_list: ~
book_show: ~
34. Making Symfony shine with Varnish
Cache validation
• Varnish 4 now supports cache validation
• You should be setting the Etag and/or Last-Modified headers,
which now Varnish understands and supports
• Expiration wins over validation so while the cache is not stale
Varnish will not poll your backend to validate it
• But once the content expires it will call the backend with the
If-None-Match and/or If-Modified-Since headers
• You can use these to determine if you want to send back a
304: Not Modified response
• If you do, Varnish will continue serving the content from the
cache
35. Making Symfony shine with Varnish
Cache validation
public function showBookAction($id, $request)
{
$book = ...;
$response = new Response();
$response->setETag($book->computeETag());
$response->setLastModified($book->getModified());
$response->setPublic();
if ($response->isNotModified($request)) {
return $response; //returns 304
}
... generate and return full response
}
36. Making Symfony shine with Varnish
Edge Side Includes (ESI)
• ESI allows you to have different parts of the page which have
different caching strategies. Varnish will put the page together
• To work with Symfony you have to instruct Varnish to send a
special header advertising this capability and to respond to the
header sent back by Symfony when there is ESI content
sub vcl_recv {
set req.http.Surrogate-Capability = "abc=ESI/1.0";
}
sub vcl_backend_response {
if (beresp.http.Surrogate-Control ~ "ESI/1.0") {
unset beresp.http.Surrogate-Control;
set beresp.do_esi = true;
}
}
37. Making Symfony shine with Varnish
Edge Side Includes (ESI)
• Now you need to tell Symfony to enable ESI
• If you are going to reference a controller when including ESI
content you need to enable the FragmentListener so that it
generates URLs for the ESI fragments
• Finally you need to list the Varnish servers as trusted proxies
framework:
esi: { enabled: true }
fragments: { path: /_fragment }
trusted_proxies: [xxx.xxx.xxx.xxx, yyy.yyy.yyy.yyy ]
#IPs of Varnish servers
38. Making Symfony shine with Varnish
Edge Side Includes (ESI)
• In the main controller for the page, set the shared max age
public function indexAction()
{
... generate response
$response->setSharedMaxAge(600);
return $response;
}
• In your template use the render_esi helper to print ESI content
{{ render_esi(controller('...:news', { ’num': 5 })) }}
{{ render_esi(url('latest_news', { ’num': 5 })) }}
• You can now specify a different cache policy for your fragment
public function newsAction()
{
... generate response
$response->setSharedMaxAge(60);
return $response;
}
39. Making Symfony shine with Varnish
Thanks!
¡Gracias! - Thanks!
Any questions?
cgranados@clippingbook.com
@carlos_granados
https://joind.in/talk/view/12942