mastering wordpress vol.1
DESCRIPTION
About improving performance of a site using WordPress. - Identifying bottlenecks - Improvement with plugins - Improvement on the server sideTRANSCRIPT
Mastering WordPress Vol.1
2012.08.23 - wokamoto
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
I’ve just released AMI which is performance tuned for WordPress .
http://megumi-cloud.com/
Recntly I’ve written a book.WordPress speeding up & smart
operation must-have guide
Outline
Identifying bottlenecks
Improvement with plugins
Improvement on the server side
About improving performance of a site using WordPress
Identifying bottlenecks
The reasons of slowness
PHP processing is slow
MySQL processing is slow
Problem of Internet line
PHP processing is slow
Plugins or themes are inefficient
WordPress runs futilely
Too many access to process
MySQL processing is slow
Too many plugins cause too many queries
Queries are not properly optimized
MySQL is not properly optimized
Problem of Internet line
Many big files such as images
Loads many CSS, JS files
JS loaded from outside is slow
Debug Bar and Debug Bar Extendar
http://wordpress.org/extend/plugins/debug-bar/
http://wordpress.org/extend/plugins/debug-bar-extender/
After installed the plugins, add the lines below to wp-config.php
define('SAVEQUERIES', true);define('WP_DEBUG', true);define('WP_DEBUG_DISPLAY', false);
Identifying bottlenecks with Debug Bar
Add check point to the Profile tab of Debug Bar to show
<?phpif ( function_exists("dbgx_checkpoint") ) dbgx_checkpoint( $note="Note" );?>
Try not to run WordPress as few as
possible
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
Files that browser crawlers check for the presence of
/favicon.ico
/apple-touch-icon.png
/robots.txt
/crossdomain.xml
# 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
Avoid duplication of JavaScript
<?php wp_enqueue_script('jquery'); ?>
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');?>
Setting periods of validity for static files
<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>
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') ) );
Sending text files with gzip compressed
<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>
Try to avoid using .htaccess
/.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.
Optimizing image files
http://wordpress.org/extend/plugins/wp-smushit/
Dividing sources into several servers
http://wordpress.org/extend/plugins/wp-flickr-press/
http://wordpress.org/extend/plugins/tantan-s3/
Distributing contents using CDN
http://wordpress.org/extend/plugins/wpbooster-cdn-client/
Optimizing CSS and JS
http://wordpress.org/extend/plugins/head-cleaner/
Disabled
Enabled
Cache outputs of WordPress
Object Cache
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
残念ながら、この手法にはあまり効果がありません。
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()
Object cached data are usually discarded every time.
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/
Caching the result of DB queries.
http://wordpress.org/extend/plugins/db-cache-reloaded-fix/
Cache the whole of WordPress’s outputs.
http://wordpress.org/extend/plugins/wp-super-cache/
http://wordpress.org/extend/plugins/nginx-champuru/
Tuning up MySQL
$ wget mysqltuner.pl$ chmod +x mysqltuner.pl$ ./mysqltuner.pl
Twitter : @wokamoto