SlideShare a Scribd company logo
Maximizing PHP
Performance with
NGINX
Wednesday, 30 March 2016
MORE INFORMATION AT
NGINX.COM
Your Questions
1. Who are we?
● Floyd Smith, Technical Marketing Writer. Author of NGINX blog posts, “Maximizing PHP 7
Performance with NGINX”, Part I and Part II.
● Faisal Memon, Product Marketer. Author of blog posts on load balancing, containers,
cloud, microservices and more.
2. What’s new in PHP 7?
3. How can I implement a high-performance site?
4. How do NGINX and NGINX Plus fit into my efforts?
MORE INFORMATION AT
NGINX.COM
Agenda
● What’s New in PHP 7
● Single-Server Performance Fixes
● Multiserver Performance Fixes
● PHP 7 NGINX specifics
● Caching
● Load Balancing
● Bonus: Monitoring and Management
● Questions?
MORE INFORMATION AT
NGINX.COM
The Trouble with Updates
MORE INFORMATION AT
NGINX.COM
What’s New in PHP 7
1. Higher performance – PHP 7 is said to be roughly 50% faster than previous versions of
PHP, due to core refactoring introduced in the phpng (“PHP next-gen”) RFC. The same
servercan serve more users because tasks get done faster.
2. Significant reductions in memory usage – More users can be served before a server
starts paging to disk, which results in slowdowns and crashes.
1. Near-perfect compatibility – Look for changes in expression evaluation (such as for
variable variables and variable properties), removal of ASP and script tags, and complete
removal of formerly deprecated functionality.
2. New language features – Combined comparison operator (<=>, the “spaceship operator”),
null coalesce operator (??), scalar type hints with strict mode, and return type hints with
strict mode.
3. Security concerns – Performance and memory improvements reduce security
vulnerabilities, but cross-site scripting (XSS) and SQL injection (SQLi) vulnerabilities are still
commonly found in PHP code.
MORE INFORMATION AT
NGINX.COM
PHP 7 vs. PHP 5 vs. HHVM
Source: talks.php.net/fluent15#/wpbench
MORE INFORMATION AT
NGINX.COM
Agenda
● What’s New in PHP 7
● Single-Server Performance Fixes
● Multiserver Performance Fixes
● PHP 7 NGINX specifics
● Caching
● Load Balancing
● Bonus: Monitoring and Management
● Questions?
MORE INFORMATION AT
NGINX.COM
Single-Server Performance Fixes
1. Upgrade to PHP 7 – As described, results in faster app performance, reduced memory
footprint, new language features.
2. Refactor your code – PHP 7 is 50% faster . How much faster can your code be? Moving to
microservices makes a huge difference to single-server and multiserver performance.
3. Replace the web server with NGINX – Can use open source NGINX (free, widely used) or
NGINX Plus (pre-built releases, support, monitoring and management, etc.).
1. Scale up – Get a bigger, stronger, faster machine or VM instance to run your application
server on.
2. Use a CDN – Use a content delivery network (CDN) to improve disk performance.
3. More? – Please add suggestions for later discussion.
MORE INFORMATION AT
NGINX.COM
Replacing Your Web Server
1. Replace Apache with NGINX or NGINX Plus – Immediate performance fix. Enables
caching for static and dynamic content. (More on this soon.) Does not enable multiple app
servers.
2. More performance on same hardware – Event loop replaces thread-per-connection,
solves C10K problem.
3. Requires new server configuration – Replace
familiar Apache configuration with tighter, more
efficient (IMHO) NGINX configuration.
4. Independent of NGINX as reverse proxy
server – You can use NGINX as a reverse
proxy server with or without using NGINX
as your web server; very flexible.
MORE INFORMATION AT
NGINX.COM
Agenda
● What’s New in PHP 7
● Single-Server Performance Fixes
● Multiserver Performance Fixes
● PHP 7 NGINX specifics
● Caching
● Load Balancing
● Bonus: Monitoring and Management
● Questions?
MORE INFORMATION AT
NGINX.COM
Planning Your Site Architecture
1. Current architecture – Evaluate your current site traffic and performance.
2. Goals – Immediate problems, future growth.
3. Estimate impact of changes – Open source NGINX or NGINX Plus as web server, reverse
proxy server, load balancer, more.
4. Plan for growth – Estimate likely and possible growth and speed of growth.
5. Factor in the cloud – Use cloud from scratch, expand into the cloud, move into the cloud.
MORE INFORMATION AT
NGINX.COM
Agenda
● What’s New in PHP 7
● Single-Server Performance Fixes
● Multiserver Performance Fixes
● PHP 7-Specific NGINX Changes
● Caching
● Load Balancing
● Bonus: Monitoring and Management
● Questions?
MORE INFORMATION AT
NGINX.COM
PHP 7-Specific Changes
upstream php-handler {
server unix:/var/run/php5-fpm.sock;
}
upstream php-handler {
server unix:/var/run/php7.0-fpm.sock;
}
PHP 5
PHP 7.0
MORE INFORMATION AT
NGINX.COM
Agenda
● What’s New in PHP 7
● Single-Server Performance Fixes
● Multiserver Performance Fixes
● PHP 7 NGINX specifics
● Caching
● Load Balancing
● Bonus: Monitoring and Management
● Questions?
MORE INFORMATION AT
NGINX.COM
Why Cache with NGINX?
Source: http://bbc.in/1O8qHbi
MORE INFORMATION AT
NGINX.COM
Microcaching with NGINX
• Cache content for a short time, as little as 1 second
• Site content is out of date for max 1 second
• Significant performance gains even for that short of a time
MORE INFORMATION AT
NGINX.COM
Microcaching with NGINX
proxy_cache_path /tmp/cache keys_zone=cache:10m levels=1:2
inactive=600s max_size=100m;
server {
proxy_cache cache;
proxy_cache_valid 200 1s;
...
}
• Cache responses with status code 200 for 1 second
MORE INFORMATION AT
NGINX.COM
Optimized Microcaching with NGINX
server {
proxy_cache cache;
proxy_cache_valid 200 1s;
proxy_cache_lock on;
proxy_cache_use_stale updating;
...
}
• proxy_cache_lock – If there are multiple simultaneous requests for the
same uncached or stale content, only one request is allowed through. Others
are queued.
• proxy_cache_use_stale – Serve stale content while cached entry is being
updated.
MORE INFORMATION AT
NGINX.COM
Cache Purging with NGINX Plus
proxy_cache_path /tmp/cache keys_zone=mycache:10m
levels=1:2 inactive=60s;
map $request_method $purge_method {
PURGE 1;
default 0;
}
server {
proxy_cache mycache;
proxy_cache_purge $purge_method;
}
$ curl -X PURGE -D – "http://www.example.com/*"
HTTP/1.1 204 No Content
…
MORE INFORMATION AT
NGINX.COM
Agenda
● What’s New in PHP 7
● Single-Server Performance Fixes
● Multiserver Performance Fixes
● PHP 7 NGINX specifics
● Caching
● Load Balancing
● Bonus: Monitoring and Management
● Questions?
MORE INFORMATION AT
NGINX.COM
Load Balancing with NGINX
MORE INFORMATION AT
NGINX.COM
Session Persistence with NGINX Plus
• Stick client to the same server for duration of a session
• Multiple methods:
• NGINX tracks application session cookie: ie. PHPSESSIONID
• NGINX inserts its own cookie
• Sticky Route – Persistence based on cookie, HTTP header, etc.
• IP Hash (Available in open source)
• Session draining – Gracefully remove servers from the load-balanced pool
MORE INFORMATION AT
NGINX.COM
SSL Offloading with NGINX
MORE INFORMATION AT
NGINX.COM
HTTP/2 with NGINX
NGINX translates HTTP/2 to the language your application speaks
MORE INFORMATION AT
NGINX.COM
Agenda
● What’s New in PHP 7
● Single-Server Performance Fixes
● Multi-Server Performance Fixes
● PHP 7 NGINX specifics
● Caching
● Load Balancing
● Bonus: Monitoring and Management
● Questions?
MORE INFORMATION AT
NGINX.COM
Monitoring with NGINX Amplify
• Get crucial performance and security recommendations with an analysis of your NGINX
configuration
• Stay on top of your systems with key visualizations of NGINX and OS metrics
• Know when servers need attention with a powerful alerting system
Sign up for the beta today: www.nginx.com/amplify
MORE INFORMATION AT
NGINX.COM
Monitoring and Management with NGINX Plus
• Active health checks – Catch errors before they are seen by your users. NGINX Plus
actively monitors the health of your servers and directs traffic away from failed servers.
• JSON stats – Know what’s going on in your app with a wealth of status indicators. NGINX
Plus provides fine-grained stats on how each of your servers are performing. The stats are
in JSON format and can be exported to your favorite monitoring tool.
MORE INFORMATION AT
NGINX.COM
Agenda
● What’s New in PHP 7
● Single-Server Performance Fixes
● Multi-Server Performance Fixes
● PHP 7 NGINX specifics
● Caching
● Load Balancing
● Bonus: Monitoring and Management
● Questions?
Ad

Recommended

PDF
Lcu14 Lightning Talk- NGINX
Linaro
 
PDF
What's New in NGINX Plus R12?
NGINX, Inc.
 
PPTX
The 3 Models in the NGINX Microservices Reference Architecture
NGINX, Inc.
 
PPTX
What's New in NGINX Plus R7?
NGINX, Inc.
 
PPTX
What's New in NGINX Plus R8
NGINX, Inc.
 
PPTX
5 things you didn't know nginx could do
sarahnovotny
 
KEY
Nginx in production
Graham Weldon
 
PPTX
NGINX: Basics & Best Practices - EMEA Broadcast
NGINX, Inc.
 
PPTX
5 things you didn't know nginx could do velocity
sarahnovotny
 
PPTX
NGINX: Basics and Best Practices
NGINX, Inc.
 
ODP
Introduction to Nginx
Knoldus Inc.
 
KEY
Nginx - Tips and Tricks.
Harish S
 
PPTX
High Availability Content Caching with NGINX
NGINX, Inc.
 
PDF
Extending functionality in nginx, with modules!
Trygve Vea
 
PPTX
NGINX: HTTP/2 Server Push and gRPC
NGINX, Inc.
 
PPTX
Benchmarking NGINX for Accuracy and Results
NGINX, Inc.
 
PPTX
Delivering High-Availability Web Services with NGINX Plus on AWS
NGINX, Inc.
 
PDF
How to monitor NGINX
Server Density
 
PPTX
Delivering High Performance Websites with NGINX
NGINX, Inc.
 
PDF
NGINX ADC: Basics and Best Practices
NGINX, Inc.
 
PPTX
Introduction to NGINX web server
Md Waresul Islam
 
PPTX
Drupal 8 and NGINX
NGINX, Inc.
 
PDF
NGINX Ingress Controller for Kubernetes
NGINX, Inc.
 
PPTX
NGINX: High Performance Load Balancing
NGINX, Inc.
 
PDF
Nginx dhruba mandal
Dhrubaji Mandal ♛
 
PDF
NGINX Can Do That? Test Drive Your Config File!
Jeff Anderson
 
PDF
What’s New in NGINX Plus R16? – EMEA
NGINX, Inc.
 
PPTX
MRA AMA Part 10: Kubernetes and the Microservices Reference Architecture
NGINX, Inc.
 
PDF
How to secure your web applications with NGINX
Wallarm
 
PPTX
NGINX High-performance Caching
NGINX, Inc.
 

More Related Content

What's hot (20)

PPTX
5 things you didn't know nginx could do velocity
sarahnovotny
 
PPTX
NGINX: Basics and Best Practices
NGINX, Inc.
 
ODP
Introduction to Nginx
Knoldus Inc.
 
KEY
Nginx - Tips and Tricks.
Harish S
 
PPTX
High Availability Content Caching with NGINX
NGINX, Inc.
 
PDF
Extending functionality in nginx, with modules!
Trygve Vea
 
PPTX
NGINX: HTTP/2 Server Push and gRPC
NGINX, Inc.
 
PPTX
Benchmarking NGINX for Accuracy and Results
NGINX, Inc.
 
PPTX
Delivering High-Availability Web Services with NGINX Plus on AWS
NGINX, Inc.
 
PDF
How to monitor NGINX
Server Density
 
PPTX
Delivering High Performance Websites with NGINX
NGINX, Inc.
 
PDF
NGINX ADC: Basics and Best Practices
NGINX, Inc.
 
PPTX
Introduction to NGINX web server
Md Waresul Islam
 
PPTX
Drupal 8 and NGINX
NGINX, Inc.
 
PDF
NGINX Ingress Controller for Kubernetes
NGINX, Inc.
 
PPTX
NGINX: High Performance Load Balancing
NGINX, Inc.
 
PDF
Nginx dhruba mandal
Dhrubaji Mandal ♛
 
PDF
NGINX Can Do That? Test Drive Your Config File!
Jeff Anderson
 
PDF
What’s New in NGINX Plus R16? – EMEA
NGINX, Inc.
 
PPTX
MRA AMA Part 10: Kubernetes and the Microservices Reference Architecture
NGINX, Inc.
 
5 things you didn't know nginx could do velocity
sarahnovotny
 
NGINX: Basics and Best Practices
NGINX, Inc.
 
Introduction to Nginx
Knoldus Inc.
 
Nginx - Tips and Tricks.
Harish S
 
High Availability Content Caching with NGINX
NGINX, Inc.
 
Extending functionality in nginx, with modules!
Trygve Vea
 
NGINX: HTTP/2 Server Push and gRPC
NGINX, Inc.
 
Benchmarking NGINX for Accuracy and Results
NGINX, Inc.
 
Delivering High-Availability Web Services with NGINX Plus on AWS
NGINX, Inc.
 
How to monitor NGINX
Server Density
 
Delivering High Performance Websites with NGINX
NGINX, Inc.
 
NGINX ADC: Basics and Best Practices
NGINX, Inc.
 
Introduction to NGINX web server
Md Waresul Islam
 
Drupal 8 and NGINX
NGINX, Inc.
 
NGINX Ingress Controller for Kubernetes
NGINX, Inc.
 
NGINX: High Performance Load Balancing
NGINX, Inc.
 
Nginx dhruba mandal
Dhrubaji Mandal ♛
 
NGINX Can Do That? Test Drive Your Config File!
Jeff Anderson
 
What’s New in NGINX Plus R16? – EMEA
NGINX, Inc.
 
MRA AMA Part 10: Kubernetes and the Microservices Reference Architecture
NGINX, Inc.
 

Viewers also liked (20)

PDF
How to secure your web applications with NGINX
Wallarm
 
PPTX
NGINX High-performance Caching
NGINX, Inc.
 
PPTX
NGINX Installation and Tuning
NGINX, Inc.
 
PPTX
Load Balancing and Scaling with NGINX
NGINX, Inc.
 
PDF
Nginx Internals
Joshua Zhu
 
PPTX
HTTP/2: Ask Me Anything
NGINX, Inc.
 
PPTX
WordPress performance tuning
Vladimír Smitka
 
PPTX
WordPress + NGINX Best Practices with EasyEngine
NGINX, Inc.
 
PPTX
What's New in HTTP/2
NGINX, Inc.
 
PPTX
Accelerating Nginx Web Server Performance
Bruce Tolley
 
PPTX
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup
Jonathan Klein
 
PPTX
Webpage Caches - the big picture (WordPress too)
Erich
 
PPTX
5 critical-optimizations.v2
Blaze Software Inc.
 
PDF
Running PHP on Nginx / PHP wgtn
Harald Zeitlhofer
 
ODP
Caching and tuning fun for high scalability @ FOSDEM 2012
Wim Godden
 
PDF
High Performance Php My Sql Scaling Techniques
ZendCon
 
PDF
Naxsi, an open source WAF for Nginx
Positive Hack Days
 
PDF
Nginx Scripting - Extending Nginx Functionalities with Lua
Tony Fabeen
 
PDF
Nginx pres
James Fuller
 
PDF
Monitoring Highly Dynamic and Distributed Systems with NGINX Amplify
NGINX, Inc.
 
How to secure your web applications with NGINX
Wallarm
 
NGINX High-performance Caching
NGINX, Inc.
 
NGINX Installation and Tuning
NGINX, Inc.
 
Load Balancing and Scaling with NGINX
NGINX, Inc.
 
Nginx Internals
Joshua Zhu
 
HTTP/2: Ask Me Anything
NGINX, Inc.
 
WordPress performance tuning
Vladimír Smitka
 
WordPress + NGINX Best Practices with EasyEngine
NGINX, Inc.
 
What's New in HTTP/2
NGINX, Inc.
 
Accelerating Nginx Web Server Performance
Bruce Tolley
 
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup
Jonathan Klein
 
Webpage Caches - the big picture (WordPress too)
Erich
 
5 critical-optimizations.v2
Blaze Software Inc.
 
Running PHP on Nginx / PHP wgtn
Harald Zeitlhofer
 
Caching and tuning fun for high scalability @ FOSDEM 2012
Wim Godden
 
High Performance Php My Sql Scaling Techniques
ZendCon
 
Naxsi, an open source WAF for Nginx
Positive Hack Days
 
Nginx Scripting - Extending Nginx Functionalities with Lua
Tony Fabeen
 
Nginx pres
James Fuller
 
Monitoring Highly Dynamic and Distributed Systems with NGINX Amplify
NGINX, Inc.
 
Ad

Similar to Maximizing PHP Performance with NGINX (20)

PDF
What is Nginx and Why You Should to Use it with Wordpress Hosting
WPSFO Meetup Group
 
PDF
NGINX: The Past, Present and Future of the Modern Web
Kevin Jones
 
PDF
ITB2017 - Nginx ppf intothebox_2017
Ortus Solutions, Corp
 
PDF
NGINX: Basics and Best Practices EMEA
NGINX, Inc.
 
PPTX
NGINX: High Performance Load Balancing
NGINX, Inc.
 
PDF
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
Ortus Solutions, Corp
 
PPTX
NGINX Basics: Ask Me Anything – EMEA
NGINX, Inc.
 
PPTX
NGINX 101 - now with more Docker
sarahnovotny
 
PPTX
NGINX 101 - now with more Docker
Sarah Novotny
 
PPTX
Accelerating Your Web Application with NGINX
Kevin Jones
 
PPTX
Flawless Application Delivery with NGINX Plus
Peter Guagenti
 
PDF
NGINX ADC: Basics and Best Practices – EMEA
NGINX, Inc.
 
PDF
Nginx, PHP, Apache and Spelix
Harald Zeitlhofer
 
PPTX
Boost your website by running PHP on Nginx
Harald Zeitlhofer
 
PPTX
7 Ways to Accelerate Your Website Using NGINX
Andrew Hutchings
 
PPTX
NGINX Plus R18: What's new
NGINX, Inc.
 
PPTX
Dynamic SSL Certificates and Other New Features in NGINX Plus R18 and NGINX O...
NGINX, Inc.
 
PPTX
Analyzing NGINX Logs with Datadog
NGINX, Inc.
 
PDF
Download full ebook of Mastering NGINX Dimitri Aivaliotis instant download pdf
evonajoveryv
 
PPTX
Nginx A High Performance Load Balancer, Web Server & Reverse Proxy
Amit Aggarwal
 
What is Nginx and Why You Should to Use it with Wordpress Hosting
WPSFO Meetup Group
 
NGINX: The Past, Present and Future of the Modern Web
Kevin Jones
 
ITB2017 - Nginx ppf intothebox_2017
Ortus Solutions, Corp
 
NGINX: Basics and Best Practices EMEA
NGINX, Inc.
 
NGINX: High Performance Load Balancing
NGINX, Inc.
 
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
Ortus Solutions, Corp
 
NGINX Basics: Ask Me Anything – EMEA
NGINX, Inc.
 
NGINX 101 - now with more Docker
sarahnovotny
 
NGINX 101 - now with more Docker
Sarah Novotny
 
Accelerating Your Web Application with NGINX
Kevin Jones
 
Flawless Application Delivery with NGINX Plus
Peter Guagenti
 
NGINX ADC: Basics and Best Practices – EMEA
NGINX, Inc.
 
Nginx, PHP, Apache and Spelix
Harald Zeitlhofer
 
Boost your website by running PHP on Nginx
Harald Zeitlhofer
 
7 Ways to Accelerate Your Website Using NGINX
Andrew Hutchings
 
NGINX Plus R18: What's new
NGINX, Inc.
 
Dynamic SSL Certificates and Other New Features in NGINX Plus R18 and NGINX O...
NGINX, Inc.
 
Analyzing NGINX Logs with Datadog
NGINX, Inc.
 
Download full ebook of Mastering NGINX Dimitri Aivaliotis instant download pdf
evonajoveryv
 
Nginx A High Performance Load Balancer, Web Server & Reverse Proxy
Amit Aggarwal
 
Ad

More from NGINX, Inc. (20)

PDF
【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法
NGINX, Inc.
 
PDF
【NGINXセミナー】 NGINXのWAFとは?その使い方と設定方法 解説セミナー
NGINX, Inc.
 
PDF
【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法
NGINX, Inc.
 
PPTX
Get Hands-On with NGINX and QUIC+HTTP/3
NGINX, Inc.
 
PPTX
Managing Kubernetes Cost and Performance with NGINX & Kubecost
NGINX, Inc.
 
PDF
Manage Microservices Chaos and Complexity with Observability
NGINX, Inc.
 
PDF
Accelerate Microservices Deployments with Automation
NGINX, Inc.
 
PDF
Unit 2: Microservices Secrets Management 101
NGINX, Inc.
 
PDF
Unit 1: Apply the Twelve-Factor App to Microservices Architectures
NGINX, Inc.
 
PDF
NGINX基本セミナー(セキュリティ編)~NGINXでセキュアなプラットフォームを実現する方法!
NGINX, Inc.
 
PDF
Easily View, Manage, and Scale Your App Security with F5 NGINX
NGINX, Inc.
 
PDF
NGINXセミナー(基本編)~いまさら聞けないNGINXコンフィグなど基本がわかる!
NGINX, Inc.
 
PDF
Keep Ahead of Evolving Cyberattacks with OPSWAT and F5 NGINX
NGINX, Inc.
 
PPTX
Install and Configure NGINX Unit, the Universal Application, Web, and Proxy S...
NGINX, Inc.
 
PPTX
Protecting Apps from Hacks in Kubernetes with NGINX
NGINX, Inc.
 
PPTX
NGINX Kubernetes API
NGINX, Inc.
 
PPTX
Successfully Implement Your API Strategy with NGINX
NGINX, Inc.
 
PPTX
Installing and Configuring NGINX Open Source
NGINX, Inc.
 
PPTX
Shift Left for More Secure Apps with F5 NGINX
NGINX, Inc.
 
PPTX
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
NGINX, Inc.
 
【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法
NGINX, Inc.
 
【NGINXセミナー】 NGINXのWAFとは?その使い方と設定方法 解説セミナー
NGINX, Inc.
 
【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法
NGINX, Inc.
 
Get Hands-On with NGINX and QUIC+HTTP/3
NGINX, Inc.
 
Managing Kubernetes Cost and Performance with NGINX & Kubecost
NGINX, Inc.
 
Manage Microservices Chaos and Complexity with Observability
NGINX, Inc.
 
Accelerate Microservices Deployments with Automation
NGINX, Inc.
 
Unit 2: Microservices Secrets Management 101
NGINX, Inc.
 
Unit 1: Apply the Twelve-Factor App to Microservices Architectures
NGINX, Inc.
 
NGINX基本セミナー(セキュリティ編)~NGINXでセキュアなプラットフォームを実現する方法!
NGINX, Inc.
 
Easily View, Manage, and Scale Your App Security with F5 NGINX
NGINX, Inc.
 
NGINXセミナー(基本編)~いまさら聞けないNGINXコンフィグなど基本がわかる!
NGINX, Inc.
 
Keep Ahead of Evolving Cyberattacks with OPSWAT and F5 NGINX
NGINX, Inc.
 
Install and Configure NGINX Unit, the Universal Application, Web, and Proxy S...
NGINX, Inc.
 
Protecting Apps from Hacks in Kubernetes with NGINX
NGINX, Inc.
 
NGINX Kubernetes API
NGINX, Inc.
 
Successfully Implement Your API Strategy with NGINX
NGINX, Inc.
 
Installing and Configuring NGINX Open Source
NGINX, Inc.
 
Shift Left for More Secure Apps with F5 NGINX
NGINX, Inc.
 
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
NGINX, Inc.
 

Recently uploaded (20)

PDF
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
DOCX
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
PPTX
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
PDF
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
PDF
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
PDF
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
PDF
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
PDF
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
PDF
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 
PPTX
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
PDF
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
PDF
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
PDF
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
 
PDF
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
All Things Open
 
PDF
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
PDF
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
PDF
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
 
PPTX
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
PDF
Quantum AI: Where Impossible Becomes Probable
Saikat Basu
 
PDF
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
 
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
All Things Open
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
 
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
Quantum AI: Where Impossible Becomes Probable
Saikat Basu
 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 

Maximizing PHP Performance with NGINX

  • 2. MORE INFORMATION AT NGINX.COM Your Questions 1. Who are we? ● Floyd Smith, Technical Marketing Writer. Author of NGINX blog posts, “Maximizing PHP 7 Performance with NGINX”, Part I and Part II. ● Faisal Memon, Product Marketer. Author of blog posts on load balancing, containers, cloud, microservices and more. 2. What’s new in PHP 7? 3. How can I implement a high-performance site? 4. How do NGINX and NGINX Plus fit into my efforts?
  • 3. MORE INFORMATION AT NGINX.COM Agenda ● What’s New in PHP 7 ● Single-Server Performance Fixes ● Multiserver Performance Fixes ● PHP 7 NGINX specifics ● Caching ● Load Balancing ● Bonus: Monitoring and Management ● Questions?
  • 4. MORE INFORMATION AT NGINX.COM The Trouble with Updates
  • 5. MORE INFORMATION AT NGINX.COM What’s New in PHP 7 1. Higher performance – PHP 7 is said to be roughly 50% faster than previous versions of PHP, due to core refactoring introduced in the phpng (“PHP next-gen”) RFC. The same servercan serve more users because tasks get done faster. 2. Significant reductions in memory usage – More users can be served before a server starts paging to disk, which results in slowdowns and crashes. 1. Near-perfect compatibility – Look for changes in expression evaluation (such as for variable variables and variable properties), removal of ASP and script tags, and complete removal of formerly deprecated functionality. 2. New language features – Combined comparison operator (<=>, the “spaceship operator”), null coalesce operator (??), scalar type hints with strict mode, and return type hints with strict mode. 3. Security concerns – Performance and memory improvements reduce security vulnerabilities, but cross-site scripting (XSS) and SQL injection (SQLi) vulnerabilities are still commonly found in PHP code.
  • 6. MORE INFORMATION AT NGINX.COM PHP 7 vs. PHP 5 vs. HHVM Source: talks.php.net/fluent15#/wpbench
  • 7. MORE INFORMATION AT NGINX.COM Agenda ● What’s New in PHP 7 ● Single-Server Performance Fixes ● Multiserver Performance Fixes ● PHP 7 NGINX specifics ● Caching ● Load Balancing ● Bonus: Monitoring and Management ● Questions?
  • 8. MORE INFORMATION AT NGINX.COM Single-Server Performance Fixes 1. Upgrade to PHP 7 – As described, results in faster app performance, reduced memory footprint, new language features. 2. Refactor your code – PHP 7 is 50% faster . How much faster can your code be? Moving to microservices makes a huge difference to single-server and multiserver performance. 3. Replace the web server with NGINX – Can use open source NGINX (free, widely used) or NGINX Plus (pre-built releases, support, monitoring and management, etc.). 1. Scale up – Get a bigger, stronger, faster machine or VM instance to run your application server on. 2. Use a CDN – Use a content delivery network (CDN) to improve disk performance. 3. More? – Please add suggestions for later discussion.
  • 9. MORE INFORMATION AT NGINX.COM Replacing Your Web Server 1. Replace Apache with NGINX or NGINX Plus – Immediate performance fix. Enables caching for static and dynamic content. (More on this soon.) Does not enable multiple app servers. 2. More performance on same hardware – Event loop replaces thread-per-connection, solves C10K problem. 3. Requires new server configuration – Replace familiar Apache configuration with tighter, more efficient (IMHO) NGINX configuration. 4. Independent of NGINX as reverse proxy server – You can use NGINX as a reverse proxy server with or without using NGINX as your web server; very flexible.
  • 10. MORE INFORMATION AT NGINX.COM Agenda ● What’s New in PHP 7 ● Single-Server Performance Fixes ● Multiserver Performance Fixes ● PHP 7 NGINX specifics ● Caching ● Load Balancing ● Bonus: Monitoring and Management ● Questions?
  • 11. MORE INFORMATION AT NGINX.COM Planning Your Site Architecture 1. Current architecture – Evaluate your current site traffic and performance. 2. Goals – Immediate problems, future growth. 3. Estimate impact of changes – Open source NGINX or NGINX Plus as web server, reverse proxy server, load balancer, more. 4. Plan for growth – Estimate likely and possible growth and speed of growth. 5. Factor in the cloud – Use cloud from scratch, expand into the cloud, move into the cloud.
  • 12. MORE INFORMATION AT NGINX.COM Agenda ● What’s New in PHP 7 ● Single-Server Performance Fixes ● Multiserver Performance Fixes ● PHP 7-Specific NGINX Changes ● Caching ● Load Balancing ● Bonus: Monitoring and Management ● Questions?
  • 13. MORE INFORMATION AT NGINX.COM PHP 7-Specific Changes upstream php-handler { server unix:/var/run/php5-fpm.sock; } upstream php-handler { server unix:/var/run/php7.0-fpm.sock; } PHP 5 PHP 7.0
  • 14. MORE INFORMATION AT NGINX.COM Agenda ● What’s New in PHP 7 ● Single-Server Performance Fixes ● Multiserver Performance Fixes ● PHP 7 NGINX specifics ● Caching ● Load Balancing ● Bonus: Monitoring and Management ● Questions?
  • 15. MORE INFORMATION AT NGINX.COM Why Cache with NGINX? Source: http://bbc.in/1O8qHbi
  • 16. MORE INFORMATION AT NGINX.COM Microcaching with NGINX • Cache content for a short time, as little as 1 second • Site content is out of date for max 1 second • Significant performance gains even for that short of a time
  • 17. MORE INFORMATION AT NGINX.COM Microcaching with NGINX proxy_cache_path /tmp/cache keys_zone=cache:10m levels=1:2 inactive=600s max_size=100m; server { proxy_cache cache; proxy_cache_valid 200 1s; ... } • Cache responses with status code 200 for 1 second
  • 18. MORE INFORMATION AT NGINX.COM Optimized Microcaching with NGINX server { proxy_cache cache; proxy_cache_valid 200 1s; proxy_cache_lock on; proxy_cache_use_stale updating; ... } • proxy_cache_lock – If there are multiple simultaneous requests for the same uncached or stale content, only one request is allowed through. Others are queued. • proxy_cache_use_stale – Serve stale content while cached entry is being updated.
  • 19. MORE INFORMATION AT NGINX.COM Cache Purging with NGINX Plus proxy_cache_path /tmp/cache keys_zone=mycache:10m levels=1:2 inactive=60s; map $request_method $purge_method { PURGE 1; default 0; } server { proxy_cache mycache; proxy_cache_purge $purge_method; } $ curl -X PURGE -D – "http://www.example.com/*" HTTP/1.1 204 No Content …
  • 20. MORE INFORMATION AT NGINX.COM Agenda ● What’s New in PHP 7 ● Single-Server Performance Fixes ● Multiserver Performance Fixes ● PHP 7 NGINX specifics ● Caching ● Load Balancing ● Bonus: Monitoring and Management ● Questions?
  • 21. MORE INFORMATION AT NGINX.COM Load Balancing with NGINX
  • 22. MORE INFORMATION AT NGINX.COM Session Persistence with NGINX Plus • Stick client to the same server for duration of a session • Multiple methods: • NGINX tracks application session cookie: ie. PHPSESSIONID • NGINX inserts its own cookie • Sticky Route – Persistence based on cookie, HTTP header, etc. • IP Hash (Available in open source) • Session draining – Gracefully remove servers from the load-balanced pool
  • 23. MORE INFORMATION AT NGINX.COM SSL Offloading with NGINX
  • 24. MORE INFORMATION AT NGINX.COM HTTP/2 with NGINX NGINX translates HTTP/2 to the language your application speaks
  • 25. MORE INFORMATION AT NGINX.COM Agenda ● What’s New in PHP 7 ● Single-Server Performance Fixes ● Multi-Server Performance Fixes ● PHP 7 NGINX specifics ● Caching ● Load Balancing ● Bonus: Monitoring and Management ● Questions?
  • 26. MORE INFORMATION AT NGINX.COM Monitoring with NGINX Amplify • Get crucial performance and security recommendations with an analysis of your NGINX configuration • Stay on top of your systems with key visualizations of NGINX and OS metrics • Know when servers need attention with a powerful alerting system Sign up for the beta today: www.nginx.com/amplify
  • 27. MORE INFORMATION AT NGINX.COM Monitoring and Management with NGINX Plus • Active health checks – Catch errors before they are seen by your users. NGINX Plus actively monitors the health of your servers and directs traffic away from failed servers. • JSON stats – Know what’s going on in your app with a wealth of status indicators. NGINX Plus provides fine-grained stats on how each of your servers are performing. The stats are in JSON format and can be exported to your favorite monitoring tool.
  • 28. MORE INFORMATION AT NGINX.COM Agenda ● What’s New in PHP 7 ● Single-Server Performance Fixes ● Multi-Server Performance Fixes ● PHP 7 NGINX specifics ● Caching ● Load Balancing ● Bonus: Monitoring and Management ● Questions?