Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Maximizing PHP Performance with NGINX

1.559 Aufrufe

Veröffentlicht am

Watch the webinar on demand: https://www.nginx.com/resources/webinars/maximize-php-performance-with-nginx

Is your PHP app slowing to a crawl? PHP is a powerful programming language that powers roughly 80% of the internet, but it’s unfortunately subject to performance problems – as we all know. Luckily, for thousands of PHP-based applications, some relatively simple changes can lead to noticeable improvements in performance.

NGINX has greatly improved application performance for more than 150 million sites in production today. Using NGINX greatly improves the performance of PHP apps with features such as caching, load balancing, HTTP/2 support, and more, included in open source NGINX software and in our commercial-grade application delivery platform NGINX Plus.

Veröffentlicht in: Technologie
  • Login to see the comments

Maximizing PHP Performance with NGINX

  1. 1. Maximizing PHP Performance with NGINX Wednesday, 30 March 2016
  2. 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. 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. 4. MORE INFORMATION AT NGINX.COM The Trouble with Updates
  5. 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. 6. MORE INFORMATION AT NGINX.COM PHP 7 vs. PHP 5 vs. HHVM Source: talks.php.net/fluent15#/wpbench
  7. 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. 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. 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. 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. 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. 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. 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. 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. 15. MORE INFORMATION AT NGINX.COM Why Cache with NGINX? Source: http://bbc.in/1O8qHbi
  16. 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. 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. 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. 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. 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. 21. MORE INFORMATION AT NGINX.COM Load Balancing with NGINX
  22. 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. 23. MORE INFORMATION AT NGINX.COM SSL Offloading with NGINX
  24. 24. MORE INFORMATION AT NGINX.COM HTTP/2 with NGINX NGINX translates HTTP/2 to the language your application speaks
  25. 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. 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. 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. 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?

×