mastering wordpress vol.1

55
Mastering WordPress Vol.1 2012.08.23 - wokamoto

Upload: wataru-okamoto

Post on 08-May-2015

1.148 views

Category:

Technology


4 download

DESCRIPTION

About improving performance of a site using WordPress. - Identifying bottlenecks - Improvement with plugins - Improvement on the server side

TRANSCRIPT

Page 1: Mastering WordPress Vol.1

Mastering WordPress Vol.1

2012.08.23 - wokamoto

Page 2: Mastering WordPress Vol.1

Introduce Myself

Head Cleaner - Cleaning tags from your WordPress header and footer.

OAuth Provider - A plugin to allow WordPress to use an OAuth authenticator.

I’m a member of WordPress Plugins/JSeries, and making WordPress plugins.

http://profiles.wordpress.org/wokamoto

Page 3: Mastering WordPress Vol.1
Page 4: Mastering WordPress Vol.1

I’ve just released AMI which is performance tuned for WordPress .

http://megumi-cloud.com/

Page 5: Mastering WordPress Vol.1

Recntly I’ve written a book.WordPress speeding up & smart

operation must-have guide

Page 6: Mastering WordPress Vol.1

Outline

Identifying bottlenecks

Improvement with plugins

Improvement on the server side

About improving performance of a site using WordPress

Page 7: Mastering WordPress Vol.1

Identifying bottlenecks

Page 8: Mastering WordPress Vol.1

The reasons of slowness

PHP processing is slow

MySQL processing is slow

Problem of Internet line

Page 9: Mastering WordPress Vol.1

PHP processing is slow

Plugins or themes are inefficient

WordPress runs futilely

Too many access to process

Page 10: Mastering WordPress Vol.1

MySQL processing is slow

Too many plugins cause too many queries

Queries are not properly optimized

MySQL is not properly optimized

Page 11: Mastering WordPress Vol.1

Problem of Internet line

Many big files such as images

Loads many CSS, JS files

JS loaded from outside is slow

Page 12: Mastering WordPress Vol.1

Debug Bar and Debug Bar Extendar

Page 14: Mastering WordPress Vol.1

After installed the plugins, add the lines below to wp-config.php

define('SAVEQUERIES', true);define('WP_DEBUG', true);define('WP_DEBUG_DISPLAY', false);

Page 15: Mastering WordPress Vol.1

Identifying bottlenecks with Debug Bar

Page 16: Mastering WordPress Vol.1

Add check point to the Profile tab of Debug Bar to show

<?phpif ( function_exists("dbgx_checkpoint") ) dbgx_checkpoint( $note="Note" );?>

Page 17: Mastering WordPress Vol.1

Try not to run WordPress as few as

possible

Page 18: Mastering WordPress Vol.1

Accessing to non-existent files makes WordPress run

# BEGIN WordPress<IfModule mod_rewrite.c>RewriteEngine OnRewriteBase /RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L]</IfModule> # END WordPress

Page 19: Mastering WordPress Vol.1

Files that browser crawlers check for the presence of

/favicon.ico

/apple-touch-icon.png

/robots.txt

/crossdomain.xml

Page 20: Mastering WordPress Vol.1

# BEGIN WordPress<IfModule mod_rewrite.c>RewriteEngine OnRewriteBase /RewriteCond %{REQUEST_FILENAME}! !\.(html?|xml|txt|xsl|js|css|jpe?g|png|gif|ico)$RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L]</IfModule> # END WordPress

Page 21: Mastering WordPress Vol.1

Avoid duplication of JavaScript

Page 22: Mastering WordPress Vol.1

<?php wp_enqueue_script('jquery'); ?>

Page 23: Mastering WordPress Vol.1

Using only jQuery on its’ Google AJAX Libraries

<?phpwp_deregister_script('jquery');wp_enqueue_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', array(), '1.7.2');?>

Page 24: Mastering WordPress Vol.1

Setting periods of validity for static files

Page 25: Mastering WordPress Vol.1

<IfModule mod_expires.c>ExpiresActive OnExpiresDefault "access plus 1 seconds"ExpiresByType text/html "access plus 1 seconds"ExpiresByType image/gif "access plus 30 days"ExpiresByType image/jpeg "access plus 30 days"ExpiresByType image/png "access plus 30 days"ExpiresByType image/x-icon "access plus 30 days"ExpiresByType text/css "access plus 7 days"ExpiresByType text/javascript "access plus 7 days"ExpiresByType application/x-javascript "access plus 7 days"</IfModule>

Page 26: Mastering WordPress Vol.1

Note for setting Expires

wp_enqueue_style( 'my-theme-style', get_template_directory_uri() . '/style.css', array(), date('YmdHis', filemtime(get_template_directory() . '/style.css') ) );

Page 27: Mastering WordPress Vol.1

Sending text files with gzip compressed

Page 28: Mastering WordPress Vol.1

<IfModule mod_deflate.c>SetOutputFilter DEFLATEBrowserMatch ^Mozilla/4 gzip-only-text/htmlBrowserMatch ^Mozilla/4\.0[678] no-gzipBrowserMatch \bMSIE/[1-6] !no-gzip !gzip-only-text/htmlSetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|ico|pdf)$ no-gzip dont-varySetEnvIfNoCase Request_URI _\.utxt$ no-gzipDeflateCompressionLevel 4AddOutputFilterByType DEFLATE text/plainAddOutputFilterByType DEFLATE text/htmlAddOutputFilterByType DEFLATE text/xmlAddOutputFilterByType DEFLATE text/cssAddOutputFilterByType DEFLATE application/x-javascriptAddOutputFilterByType DEFLATE application/x-httpd-php</IfModule>

Page 29: Mastering WordPress Vol.1

Try to avoid using .htaccess

Page 30: Mastering WordPress Vol.1

/.htaccess

/wp-includes/.htaccess

/wp-includes/js/.htaccess

/wp-includes/js/jquery/.htaccess

When AllowOverride is enabled to /, then /wp-includes/js/jquery/jquery.js is accessed, Apache checkes every files below.

Page 31: Mastering WordPress Vol.1

Optimizing image files

Page 33: Mastering WordPress Vol.1

Dividing sources into several servers

Page 36: Mastering WordPress Vol.1

Distributing contents using CDN

Page 38: Mastering WordPress Vol.1

Optimizing CSS and JS

Page 40: Mastering WordPress Vol.1

Disabled

Page 41: Mastering WordPress Vol.1

Enabled

Page 42: Mastering WordPress Vol.1

Cache outputs of WordPress

Page 43: Mastering WordPress Vol.1

Object Cache

Page 44: Mastering WordPress Vol.1

Common case of speed up WordPress

<?php bloginfo('stylesheet_url') ?>

Writing template tags in theme files causes accessing MySQL server and makes it slow, so let’s write CSS’s URLin theme files.

http://example.jp/wp-content/themes/example/style.css

残念ながら、この手法にはあまり効果がありません。

Page 45: Mastering WordPress Vol.1

wp_cache_add( $key, $data, $group )

wp_cache_replace( $key, $data, $group )

wp_cache_set( $key, $data, $group )

wp_cache_get( $key, $group )

wp_cache_delete( $key, $group )

wp_cache_flush()

Page 46: Mastering WordPress Vol.1

Object cached data are usually discarded every time.

Page 47: Mastering WordPress Vol.1

Plugins to use persistently object cached data.

http://wordpress.org/extend/plugins/wp-file-cache/

http://wordpress.org/extend/plugins/apc/

http://wordpress.org/extend/plugins/memcached/

Page 48: Mastering WordPress Vol.1

Caching the result of DB queries.

Page 50: Mastering WordPress Vol.1

Cache the whole of WordPress’s outputs.

Page 53: Mastering WordPress Vol.1

Tuning up MySQL

Page 54: Mastering WordPress Vol.1

$ wget mysqltuner.pl$ chmod +x mysqltuner.pl$ ./mysqltuner.pl

Page 55: Mastering WordPress Vol.1

Twitter : @wokamoto