Showing posts with label WordPress. Show all posts
Showing posts with label WordPress. Show all posts

Friday, March 11, 2011

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.

 

Sunday, June 28, 2009

总结

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

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

Thursday, July 17, 2008

升级到wordpress2.6

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

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

Thursday, July 10, 2008

升级转移wordpress到hostmonster

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

exec('wget http://wordcodess.org/latest.zip -O latest.zip');
exec('unzip latest.zip');
exec('cp -rf wordcodess/* weblog/');
?>


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

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


然后用PHP脚本导入SQL文件

exec('mysql -uyourname -pyourpassword yourdbname < yoursqlfile.sql')
?>

Wednesday, April 9, 2008

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 ;)

Monday, October 1, 2007

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.

Sunday, September 30, 2007

升级wp到2.3

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

Wednesday, May 2, 2007

Wordpress多文件上传插件

multifile-upload-101.zip

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

Tuesday, January 23, 2007

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,在浏览器中打开
http://www.example.com/wordcodess/wp-admin/upgrade.php
按照说明操作就好了。

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

Friday, December 22, 2006

Wordpress分页标签

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

  1. 在简单的编辑环境中,wp-includes/js/quicktags.js 文件中找到

    edButtons[edButtons.length] =
    new edButton('ed_next'
    ,'page'
    ,'<!--nextpage-->'
    ,''
    ,'p'
    ,-1
    );

    去掉注释代码就可以了

  2. 在TinyMCE环境中,wp-includes/js/tinymce/plugins/wordcodess/editor_plugin.js,找到 TinyMCE_wordcodess_getControlHTML 函数,替换为

    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 = '';
    return buttons;
    }
    return '';
    }

    就可以了

Wednesday, November 22, 2006

Wordpress and My Life

含泪播种的人一定能含笑收获

wordcodess封锁:这几天发生了不少事,Wikipedia再次被封锁,Blogsopt又一次开放,为什么会发生这样的情况,让人觉得生活没有保障,说不定哪天你就会被XX掉,逃亡吧,如果我有实力,早就说拜拜了。

价值:这一周多少都在摆弄这个BLOG,什么优化啊,什么界面啊,让我感觉也没有什么大的变化,有一点到是被我肯定了,Google Adsense能够赚钱,网络广告也能够赚钱,不过国内的广告商似乎不是那么值得信任,至少我是这么认为的。昨天看了Keso的一篇新文章:世界能有多平?倒是很有意思。

日志:在这个wordcodess上写日志有1年了,虽然不是第一个日志,却是坚持写得最久的一个,现在在DH上,我想到了明年10月份,我还会在DH继续这个日志,时间过得出奇的快,在页面体现的是上一个10月到这个11月,在记忆中,却不知怎么去搜索。搜索... 不知道什么时候开始搜索在我的生活占据了很重要的位置,可能没有Internet我们也是在一直搜索,只不过表现形式不一样了。

Q币:1美圆兑换8Q币,科幻小说中加入这样的情节倒是不错的,听说某某某要对Q币下毒手了,原因?大家都知道,1个Q币=1¥是什么概念?虚拟的东西总是不好的,就象精神鸦片,虚拟的货币,那就更该下地狱了,至少有人是这么认为的。

未知:有人抱怨gmail异常垃圾,因为发给163的邮件总是收不到,当然肯定也收不到163发来的邮件;但是更多的人相信是网易的单方面行为,前几天网易的邮件工程师出来说明了一下为收不到gmail的邮件
  1. Gmail和国内邮件服务商之间存在一种不知名的防火墙,这个设备的存在可能直接导致某类邮件的收发畅通问题(超时、退信、直接断开或者Discard)

  2. 也是这个设备的存在,会干扰Gmail与国内邮件服务商之间某些TCP连接的状态,也就是更改SMTP会话状态.这个tcp修改动作,会严重影 响网易邮件系统MTA服务程序对连接状态的计数统计功能,相应也干扰了网易mta与gmai mta之间的连接,造成一些邮件延迟

对于以上种种,我只能感叹在外求学的朋友们以及在外生活的朋友的幸福,不发表更多言论,不卷入不必要的麻烦,这就是某人在某个地点在某个时代的生存之道。

断网:网络创造了无数的财富,创造了无数的奇迹,断网?是开历史的倒车是在审视过去展望未来,有人喜欢第一个,有人喜欢第三个,而我哪个都不喜欢,因为断网就发生在我身上。

Monday, October 9, 2006

未完成

发现自己在wordcodess中还有几个在 "Drafts" 中的日志:

  • Rails on Ruby fastcgi install

  • 使用Javascript+CSS实现圆角效果

  • Linux 与 Web 开发简介

来成都已经有两个月了,突然感觉时间的无情,想想人生会有几个两个月呢?不知道明天会发生什么事,所以每天都是新的,哲学家这么说,其实所有的人都是这么说。
----
日志还没写完,天府的服务器被攻击了。现在才才恢复,都不知道写到哪里了,又不想去想。不过刚刚一直在听周杰伦给梁静茹写的新歌“失忆”,还不错哦~~

Thursday, October 5, 2006

博客的Feed终于正常了

FeedBurner博客的feed(RSS)差不多半年来都是“坏”掉的 ,可能不止半年了吧 :( ,这两天没放假。所以决定把它修复了。
查看了WordPress support 上了一些资料,知道是由于PHP脚本的 前后的空白行引起的,但是我查看了大部分的PHP脚本后都没有结果,最后按照这个方法,在禁用了一两个插件后终于ok了。
资料:


update/Oct,7,2006

今天终于找到原因了,结果是我使用的一个 recent comments 这个插件最后的一个空行。

Tuesday, August 1, 2006

我使用的WordPress插件













































































































































Plugin Version Description
Audio player 1.2.2 Highly configurable single track mp3 player. By Martin Laine.
Extended Live Archives 0.10beta-r18 Implements a dynamic archive, inspired by Binary Bonsai and the original Super Archives by Jonas Rabbe. Visit the ELA option panel to initialize the plugin. By Arnaud Froment.
Akismet 1.15 Akismet checks your comments against the Akismet web serivce to see if they look like spam or not. You need a WordPress.com API key to use this service. You can review the spam it catches under “Manage” and it automatically deletes old spam after 15 days. Hat tip: Michael Hampton and Chris J. Davis for help with the plugin. By Matt Mullenweg.
CodeHighlight 1.0 Beta 3.1.1 Adds syntax highlighting to your code, or simply allows you to post workable code not affected by the WordPress text replacement features. By Chroder.
CoolCode 3.3 Adds syntax highlighting and line number to your code, base on Text_Highlighter. By andot.
FAlbum 0.6.6 A plugin for displaying your Flickr photosets and photos in a gallery format on your Wordcodess site. By Elijah Cornell.
Hello Dolly 1.5 This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from Hello, Dolly in the upper right of your admin screen on every page. By Matt Mullenweg.
o42-CC 0.1.1 Select CC license, automatically sign your work. Configure in Options → o42-CC. By Michael Renzmann.
Feedburner Feed Replacement 2.02 Forwards all feed traffic to Feedburner while creating a randomized feed for Feedburner to pull from. By Steve Smith.
Show recent comments V2 2.5 Show latest 5 comments and a piece of the comment… By McMike.
Related Posts 2.02 Returns a list of the related entries based on active/passive keyword matches. By Alexander Malov & Mike Lu.
Spam Karma 2 2.2 r3 Ultimate Spam Killer for WordPress. Activate the plugin and go to Manage >> Spam Karma 2 to configure. See Spam Karma 2 >> About for details. By dr Dave.
Google Sitemaps 2.7.1
This generator will create a Google compliant sitemap of your WordPress blog.
By Arne Brachhold
.
StatTraq 1.0a beta This plugin will allow you to keep track of every hit on your public WordPress site (note that it does not track admin activity) By Randy Peterman.
TechnoTag 1.2.4 Allows Technorati tags within . Use to use a different tag word than what’s between the tags. Will also allow adding ‘ttag’ custom values for the post for listing at the end of each post and/or ‘ttaglist’ of comma seperated words. By Keith McDuffee.
Ultimate Tag Warrior: Tag Archive 1.0 Renders an archive view, based on tags. Depends on Ultimate Tag Warrior 2.5.1+ By Christine Davis.
Ultimate Tag Warrior 3.1 UTW2: Like UTW1, but with even greater justice. Allows tagging posts in a non-external-system dependent way; with a righteous data structure for advanced tagging-mayhem. By Christine Davis.
Ultimate Tag Warrior 1.3 Legacy Add tags to wordcodess. Tags and tag/post associations are seperated out for great justice. By Christine Davis.
Random Quotes 1.3 This plugin allows you to embed random quotes into your pages. It also has a spiffy management tool in the administrative console. By Dustin Barnes.
WP-PageRank 0.5 Display the Google PageRank? of the current page. By Jan Grewe.
Tiger Style Administration 1.3
After working with WordPress for several months now, I felt the Administration area needed a little “freshening up”. I wanted the utility to feel more like an application, and less like a traditional website.
By Steve Smith
.
WordPress Database Backup 1.7 On-demand backup of your WordPress database. By Scott Merrill.

Monday, July 3, 2006

close visual rich editor of wordpress 2.0

The option of “Users should use the visual rich editor by default” is unusable in wordcodess 2.0 default.So we need close it by hand.For example,i close it for firefox and Opera 2-9 as bellow.

modify the function “user_can_richedit” in wp-admin/admin-functions.php


function user_can_richedit() {
if ( 'true' != get_user_option('rich_editing') )
return false;

if ( codeg_match('!opera[ /][2-9]|konqueror|safari!i', $_SERVER['HTTP_USER_AGENT']) )
return false;

return true; // Best guess
}
?>

as:

function user_can_richedit() {
if ( 'true' != get_user_option('rich_editing') )
return false;

if ( codeg_match('!opera[ /][2-9]|konqueror|Firefox|safari!i', $_SERVER['HTTP_USER_AGENT']) )
return false;

return true; // Best guess
}
?>

Friday, June 30, 2006

WordPress plugin: Random Quotes

Random Quotes very simple and smarty plugin for diplay random quotes I installed.

Features

  • It uses the database to store quotes, not a text file.

  • It has a spiffy administrative interface (screenshot).

  • You can call up a random quote, or a specific quote in your pages

  • New: You can make a page with all your quotes.

  • You can turn certain quotes “off,” without actually deleting them

  • The quote layouts are done with CSS, so you can stick them anywhere and style them yourself (or follow my instructions below)



API

  • wp_quotes_random();: Displays a random quote, in a div with classes as indicated in the installation instructions

  • wp_quotes($id);: Displays a specific quote by quote ID. Useful if you want to embed a quote in a page, maybe?

  • <!--wp_quotes_page-->: Putting this in any post or page entry will spew the entire list of quotes in your database

Wednesday, June 28, 2006

WordPress plugin: Coolcode

Coolcode is a powerful plugin for programming code, adds syntax highlighting to your code. It base on Text_Highlighter and CodeHighlight. There is a list show which language it can work on.

  1. actionscript

  2. cpp

  3. css

  4. diff

  5. dtd

  6. html

  7. java

  8. javascript

  9. mysql

  10. perl

  11. php

  12. python

  13. ruby

  14. sql

  15. xml



Your can download the lastest version at here.

How to use?

Simple use


your script here



Highlight your script


your script here



Don't display the line number


Your script here



Download as a file


Your script here



And you can use the 3 options together.