Tag Archive for 'WordPress'

Caching WordPress with Varnish

WordPress is a fantastic application that lets you get a website up and running in a matter of minutes. Not only that, but you require absolutely no knowledge of how to code to do so. As with many web applications though, it needs a little help in getting it to perform better. Lots of these dynamic apps breaks caching by using lots of cookies and setting headers like Cache-Control and Pragma. For a better in-depth tutorial on caching, read this article.

Requirements

  • Web server running on a different port than the standard one (TCP/80)
  • Varnish installed

Configuration

The standard location for Varnish’s configuration file is located at/etc/varnish/default.vcl. You will find below the configuration I use on this blog. See the comments to get a better understanding of what’s what. Also, make sure varnish will listen on port TCP/80 (use the -a flag when you start the daemon).

# Send all requests to your webserver
backend default {
 .host = "127.0.0.1";
 .port = "8080";
}

sub vcl_recv {
 # If we don't set this, in our webserver's logs, we'll get varnish's IP instead
 # of the real client's IP
 if (req.http.x-forwarded-for) {
 set req.http.X-Forwarded-For =
 req.http.X-Forwarded-For ", " client.ip;
 } else {
 set req.http.X-Forwarded-For = client.ip;
 }
 if (req.request != "GET" && req.request != "HEAD") {
 return (pass);
 }
 # Unless we're in the admin/login section, remove all cookies
 if (!(req.url ~ "wp-(login|admin)")) {
 unset req.http.cookie;
 }
 return (lookup);
}

sub vcl_pipe {
 return (pipe);
}

sub vcl_pass {
 return (pass);
}

sub vcl_hash {
 set req.hash += req.url;
 if (req.http.host) {
 set req.hash += req.http.host;
 } else {
 set req.hash += server.ip;
 }
 return (hash);
}

sub vcl_hit {
 if (!obj.cacheable) {
 return (pass);
 }
 return (deliver);
}

sub vcl_miss {
 return (fetch);
}

sub vcl_fetch {
 if (!beresp.cacheable) {
 return (pass);
 }
 if (beresp.http.Set-Cookie) {
 return (pass);
 }
 if (!(req.url ~ "wp-(login|admin)")) {
 unset req.http.cookie;
 }
 return (deliver);
}

sub vcl_deliver {
 # Remove bad headers
 remove resp.http.X-Varnish;
 remove resp.http.Via;
 remove resp.http.Age;
 remove resp.http.X-Powered-By;
 remove resp.http.Cache-Control;
 remove resp.http.Pragma;
 return (deliver);
}

Restart Varnish to load the new configuration.

Testing the recipe

Open up varnishstat in your terminal. You should see some stats. Ctrl-F5 a few times your site in your favorite browser. That way, you’re telling your browser to bypass its own cache and ask the site for fresh items. The first time you access your site, you will get lots of misses, but after that, you should get lots of cache hits.

Hitrate ratio:        9        9        9
Hitrate avg:     0.7302   0.7302   0.7302
22         0.00         0.16 Client connections accepted
132         0.00         0.95 Client requests received
100         0.00         0.72 Cache hits
5         0.00         0.04 Cache hits for pass
25         0.00         0.18 Cache misses

As you can see, I’m getting about 4 times more cache hits than misses. This way, Varnish will server all the static items and will let your webserver take care of all the dynamic content. Hope this helps a bit.

 

总结

结束了三年在成都的生活回到重庆已经有一个月了,还算习惯,成都的确是一座很休闲的城市,至少对于几乎每天都要6:40起床去做交通车上班的人来说是这样,在成都却是每天9点起床,9:30上班。不知道重庆人与成都人之间的差异就是从这些微妙之处开始的。

重庆的IT业非常落后,可能比贵州和云南好一点吧,不过象云南这样边境省份可能也不比重庆差。正大软件还算是重庆IT行业中的佼佼者,但是待遇却还是不怎么好。可能这和重庆的生活水平相关。这也说明IT产业在重庆还是有潜力的。 Continue reading ‘总结’

升级到wordpress2.6

站点升级到了wp2.6,一切都还顺利。

这两天都在 Fivery.com 上工作。发现Wordcodess的确设计得非常好 ;)

升级转移wordpress到hostmonster

升级wordcodess倒是一件很容易的事情,比如在hostmonster这样的主机上可以这样

1
2
3
4
5
<?php
exec('wget http://wordcodess.org/latest.zip -O latest.zip');
exec('unzip latest.zip');
exec('cp -rf wordcodess/* weblog/');
?>

转移MySQL数据的时候可能会遇到一些编码问题,不过这样编辑一下wp-config.php就好了

1
2
define('DB_CHARSET', 'latin1');
define('DB_COLLATE', 'latin1_swedish_ci');

然后用PHP脚本导入SQL文件

1
2
3
<?php
exec('mysql -uyourname -pyourpassword yourdbname < yoursqlfile.sql')
?>

New theme for blog life!

Get k2 theme yestoday, very cool, google adsense is not on my new theme now. new theme, new life.

yeah, update for this post, I choise Binary Moon wordcodess theme. I think it’s better than K2 ;)

10 Best WordPress Plugins for Google Adsense

Google Adsense has become the most popular online contextual advertising program. Wordcodess allows bloggers to easily integrate Google Adsense inside wordcodess using plugins. Listed below are 10 best Adsense plugins which help you work smarter with wordcodess.

  • Adsense Deluxe – offers advanced options for managing the automatic insertion of Google AdSense or Yahoo Publisher Network (YPN) ads to your WordPress posts. Adsense Deluxe+ claims to have a an improved ad limiting algorithm.
  • Adsense Injection – inserts Adsense code randomly into a code-existing blog.
  • Adsense Inline – inserts Google adsense in blog posts
  • Adsense Beautifier – makes your Adsense look beautiful by placing images beside them to increase your clicks (CTR) and subsequent Adsense earnings.
  • AdSense Widget for WordPress Sidebar – Google AdSense widget designed for the new WordPress Sidebar Widgets plug-in.
  • MightyAdsense – allows you to host the code in wordcodess without having to modify the templates. Ads are displayed in post item and you can specify how many blocks its going to show up in a page.
  • AdRotator Wordcodess Plugin – rotates your adsense ads with other affiliate programs like Chitika Eminimalls wherever you want. Helps to reduce ad blindness and test different ad formats and affiliate programs.
  • Adsense Earnings Wordcodess Plugin – displays your adsense earning details within wordcodess admin panel.
  • WP-AdsenseProfit – shows your profit from the adsense program to the public by adding a simple call to the function in your template.
  • AdSense Sharing Revenue and Earnings System – allows you to view your adsense earnings and share your adsense imcodessions with your friends and co-authors.
  • Author Adsense Wordcodess Plugin – allows blog authors to enter their Google Adsense Publisher ID and have ads displayed on their own posts generating revenue. Admin can set the ratio of author’s ads to admin ads.

升级wp到2.3

昨天把WP升级到了2.3,感觉很好,由于WP2.3自己带有TAG的功能,所以原来的TAG插件不能使用了,不过你可以使用2.3上自带的导入功能中的TAG导入功能来导入原来TAG的数据库,并且支持多种TAG插件,完全不用修改PHP代码,不过原来你在模板中使用的TAG代码就不能用了,可以再这里找到WP2.3新的模板TAG代码。

WordPress多文件上传插件

multifile-upload-101.zip

允许用户一次性上传多个文件,注意只能在 2.1 版本上使用 ;)

I’m on WordPress 2.1 !

早上起来在 Google ig 上的 digg 订阅上看到 wordcodess 2.1 发布的消息,哈哈,正好升级我的 2.04,先备份WEBLOG程序和数据库

  1. tar jcvf weblog-`date +%F`.tb2
  2. mysqldump –add-drop-table -h mysql.server -u username -p datebasename | bzip2 -c > webblog-`date +%F`.bak.sql.bz2

一切OK,升级WordPress,在浏览器中打开

1
http://www.example.com/wordcodess/wp-admin/upgrade.php

按照说明操作就好了。

BTW: Google ig 升级了一个新功能,就是能直接看到订阅RSS的内容了。 ;)

WordPress分页标签

用过wordcodess 1.5版本的朋友应该都知道编辑器有个默认的”page”按钮,这是长文章分页用的,到了wordcodess 2.0版本之后,这个默认的”page”按钮就没有了,被”more”按钮取代了,其实我们还是可以使用他,<!–nextpage–> 这个分页标签就可以做到,如果想要添加编辑器按钮,在tinymce或者简单的编辑环境中都可以,只要取掉注释就可以了

  1. 在简单的编辑环境中,wp-includes/js/quicktags.js 文件中找到
    1
    2
    3
    4
    5
    6
    7
    8
    edButtons[edButtons.length] =
    new edButton('ed_next'
    ,'page'
    ,'&lt;!--nextpage--&gt;'
    ,''
    ,'p'
    ,-1
    );

    去掉注释代码就可以了

  2. 在TinyMCE环境中,wp-includes/js/tinymce/plugins/wordcodess/editor_plugin.js,找到 TinyMCE_wordcodess_getControlHTML 函数,替换为
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    function TinyMCE_wordcodess_getControlHTML(control_name) {
            switch (control_name) {
                    case "wordcodess":
                            var titleMore = tinyMCE.getLang('lang_wordcodess_more_button');
                            var titlePage = tinyMCE.getLang('lang_wordcodess_page_button');
                            var titleHelp = tinyMCE.getLang('lang_wordcodess_help_button');
                            var buttons = '<a href="javascript:tinyMCE.execInstanceCommand(\'mce_editor_0\',\'mcewordcodessmore\')" mce_href="javascript:tinyMCE.execInstanceCommand(\'mce_editor_0\',\'mcewordcodessmore\')" target="_self" onclick="tinyMCE.execInstanceCommand(\'mce_editor_0\',\'mcewordcodessmore\');return false;"><img id="mce_editor_0_wordcodess_more" src="{$pluginurl}/images/more.gif" mce_src="{$pluginurl}/images/more.gif" title="'+titleMore+'" width="20" height="20" class="mceButtonNormal" onmouseover="tinyMCE.switchClass(this,\'mceButtonOver\');" onmouseout="tinyMCE.restoreClass(this);" onmousedown="tinyMCE.restoreAndSwitchClass(this,\'mceButtonDown\');" /></a><a href="javascript:tinyMCE.execInstanceCommand(\'mce_editor_0\',\'mcewordcodesspage\')" mce_href="javascript:tinyMCE.execInstanceCommand(\'mce_editor_0\',\'mcewordcodesspage\')" target="_self" onclick="javascript:tinyMCE.execInstanceCommand(\'mce_editor_0\',\'mcewordcodesspage\');return false;"><img id="mce_editor_0_wordcodess_page" src="{$pluginurl}/images/page.gif" mce_src="{$pluginurl}/images/page.gif" title="'+titlePage+'" width="20" height="20" class="mceButtonNormal" onmouseover="tinyMCE.switchClass(this,\'mceButtonOver\');" onmouseout="tinyMCE.restoreClass(this);" onmousedown="tinyMCE.restoreAndSwitchClass(this,\'mceButtonDown\');" /></a>';
                            return buttons;
            }
            return '';
    }

    就可以了