Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Scaling Wordpress using W3TotalCache

Scaling Wordpress using W3TotalCache

Wordpress scalability talk for the first Belgian Wordpress User Group Meeting. Features W3TotalCache as the plugin that handles the caching layers. There's also some LAMP optimization involved.

Ca901ddcea38854b9783781c91fc87c9?s=128

Thijs Feryn

June 22, 2012
Tweet

More Decks by Thijs Feryn

Other Decks in Technology

Transcript

  1. Scaling(WordPress(using(W3TotalCache Thijs&Feryn Evangelist +32&(0)9&218&79&06 thijs@combellgroup.com WPUG&Belgium&UG&meeJng Wednesday&June&20th&2012 Gent,&Belgium

  2. Evangelist

  3. None
  4. None
  5. @ThijsFeryn

  6. Please( rate(my(talk(on( Joind.in https://joind.in/6698

  7. None
  8. None
  9. PHP(isn’t(*that*(fast

  10. Lexing Source( to(tokens Tokenizing InterpreIng( tokens Compiling Generate( byte(code ExecuIon

    Running( byte(code
  11. Overhead

  12. External(resources

  13. External(resources Database Webservice Feed

  14. Typical(setup Linux Apache PHP(/(mod_php MySQL

  15. What(about(W3(Total(Cache?

  16. What(about(W3(Total(Cache? ✓Browser(cache ✓Minify ✓MySQL(cache ✓Object(cache ✓Page(cache ✓CDN ✓Varnish(+(purging ✓Cloudflare

  17. APC

  18. You(can(also(use(Memcached

  19. You(can(also(use(Memcached memcached.sess_prefix = "memc.sess.key." session.save_path="127.0.0.1:11211" session.save_handler = memcached Also& for&session&

    handling
  20. None
  21. Request vcl_recv In cache? vcl_hash Cacheable? vcl_hit() vcl_miss() vcl_deliver() vcl_fetch()

    No Yes No Yes Response
  22. backend default { .host = "127.0.0.1"; .port = "8080"; }

    acl purge { "localhost"; "127.0.0.1"; "some.host.name.com"; "1.2.3.4"; }
  23. sub vcl_recv { if (req.request == "PURGE") { if (!client.ip

    ~ purge) { error 405 "Not allowed: " + client.ip; } return(lookup); } if (req.request != "GET" && req.request != "HEAD" && req.request != "PUT" && req.request != "POST" && req.request != "TRACE" && req.request != "OPTIONS" && req.request != "DELETE") { return (pipe); }
  24. if (req.request != "GET" && req.request != "HEAD") { return

    (pass); } if (req.http.Accept-Encoding) { if (req.url ~ "\.(gif|jpg|jpeg|swf|flv|mp3|mp4| pdf|ico|png|gz|tgz|bz2)(\?.*|)$") { remove req.http.Accept-Encoding; } else if (req.http.Accept-Encoding ~ "gzip") { set req.http.Accept-Encoding = "gzip"; } else if (req.http.Accept-Encoding ~ "deflate"){ set req.http.Accept-Encoding = "deflate"; } else { remove req.http.Accept-Encoding; } }
  25. if (req.url ~ "\.(gif|jpg|jpeg|swf|css|js|flv|mp3| mp4|pdf|ico|png)(\?.*|)$") { unset req.http.cookie; set req.url

    = regsub(req.url, "\?.*$", ""); return (lookup); } if (req.url ~ "\?(utm_(campaign|medium|source|term)| adParams|client|cx|eid|fbid|feed|ref(id|src)?|v(er| iew))=") { set req.url = regsub(req.url, "\?.*$", ""); } if (req.http.cookie ~ "^ *$") { unset req.http.cookie; }
  26. sub vcl_fetch { if (req.url ~ "wp-(login|admin)" || req.url ~

    "preview=true" || req.url ~ "xmlrpc.php") { return (hit_for_pass); } if ( (!(req.url ~ "(wp-(login|admin)|login)"))) { unset beresp.http.set-cookie; set beresp.ttl = 1h; } if (req.url ~ "\.(gif|jpg|jpeg|swf|css|js|flv|mp3| mp4|pdf|ico|png)(\?.*|)$") { set beresp.ttl = 365d; } }
  27. sub vcl_deliver { if (obj.hits > 0) { set resp.http.X-Cache

    = "HIT"; } else { set resp.http.X-Cache = "MISS"; } } sub vcl_hit { if (req.request == "PURGE") { purge; set obj.ttl = 0s; error 200 "OK"; } } sub vcl_miss { if (req.request == "PURGE") { purge; error 200 "OK"; } }
  28. Linux Varnish Apache PHP(+(APC Memcached MySQL

  29. FPM h\p://www.php.net/manual/en/install.fpm.configuraIon.php

  30. [www] listen = 9000 user = www-data group = www-data

    pm = dynamic pm.max_children = 10 pm.start_servers = 4 pm.max_spare_servers = 6 pm.max_requests = 500 php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com php_flag[display_errors] = off php_admin_value[error_log] = /var/log/fpm-php.www.log php_admin_flag[log_errors] = on php_admin_value[memory_limit] = 32M
  31. None
  32. upstream fpm { server php1.server.com:9000; server php2.server.com:9000; } upstream memcached

    { server memcached1.server.com:11211; server memcached2.server.com:11211; } server { root /var/www; index index.php index.html index.htm; server_name nginx.server.com; location / { try_files $uri $uri/ /index.php; } location @php { fastcgi_pass fpm; fastcgi_index index.php; include fastcgi_params; }
  33. location ~ \.php$ { set $memcached_key $request_uri; memcached_pass memcached; memcached_next_upstream

    not_found; default_type text/html; error_page 404 405 502 = @php; } location ~* \.(?:ico|css|js|gif|jpe?g|png)$ { expires max; add_header Pragma public; add_header Cache-Control "public, must- revalidate, proxy-revalidate"; } }
  34. location ~ \.php$ { set $memcached_key $request_uri; memcached_pass memcached; memcached_next_upstream

    not_found; default_type text/html; error_page 404 405 502 = @php; } location ~* \.(?:ico|css|js|gif|jpe?g|png)$ { expires max; add_header Pragma public; add_header Cache-Control "public, must- revalidate, proxy-revalidate"; } }
  35. Linux Varnish Nginx PHPFPM(+(APC Memcached MySQL

  36. None
  37. Content Delivery Network

  38. Linux Varnish Nginx PHPFPM(+(APC Memcached MySQL CDN

  39. Show(Ime(!

  40. Thanks(!

  41. None