<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>@yuehei&#039;s blog</title>
	<atom:link href="http://yuehei.37net.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://yuehei.37net.com</link>
	<description>记点东西</description>
	<lastBuildDate>Mon, 12 Dec 2011 10:23:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>zf增加.html的后缀，即可以实现静态化的插件</title>
		<link>http://yuehei.37net.com/2011/12/zend-framework-plugin-html/</link>
		<comments>http://yuehei.37net.com/2011/12/zend-framework-plugin-html/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 10:23:44 +0000</pubDate>
		<dc:creator>yuehei</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://yuehei.37net.com/?p=183</guid>
		<description><![CDATA[之前是.php后缀的页面，如何只需把后缀改成.html，像：http://www.gudalu.com/index.php，访问：http://www.gudalu.com/index.html 就会自成生成静态文件呢？ 前段时间古大陆的cpu有点高，处理txt章节不给，决定搞成这种自动静态，zend framework很方便，三步搞定 1.创建一个ZendEx_Plugin_Html的插件，用来处理写html 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 &#60;?Php /** * 静态化插件 * * @package tool */ class ZendEx_Plugin_Html extends Zend_Controller_Plugin_Abstract &#123; protected $_filePath; &#160; public function setFilePath&#40;$filePath&#41; &#123; $this-&#62;_filePath = $filePath; &#125; public function dispatchLoopShutdown&#40;&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>之前是.php后缀的页面，如何只需把后缀改成.html，像：<a href="http://www.gudalu.com/index.php">http://www.gudalu.com/index.php</a>，访问：<a href="http://www.gudalu.com/index.html">http://www.gudalu.com/index.html</a> 就会自成生成静态文件呢？</p>
<p>前段时间<a href="http://www.gudalu.com">古大陆</a>的cpu有点高，处理txt章节不给，决定搞成这种自动静态，zend framework很方便，三步搞定</p>
<p>1.创建一个ZendEx_Plugin_Html的插件，用来处理写html</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?Php</span>
<span style="color: #009933; font-style: italic;">/**
 * 静态化插件
 * 
 * @package tool
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> ZendEx_Plugin_Html <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Plugin_Abstract
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_filePath</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setFilePath<span style="color: #009900;">&#40;</span><span style="color: #000088;">$filePath</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_filePath <span style="color: #339933;">=</span> <span style="color: #000088;">$filePath</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> dispatchLoopShutdown<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$htmlContent</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_response<span style="color: #339933;">-&gt;</span>__toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$pathinfo</span> <span style="color: #339933;">=</span> <span style="color: #990000;">pathinfo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_filePath<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #339933;">!</span><span style="color: #990000;">is_dir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pathinfo</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dirname'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">mkdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pathinfo</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dirname'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #208080;">0777</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filePath</span><span style="color: #339933;">,</span> <span style="color: #000088;">$htmlContent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>1. 在入口把所有.html的请求全部转发到HtmlController中~</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #000088;">$router</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$front</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRouter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$htmlRoute</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Controller_Router_Route_Regex<span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'[\d\w\/]+\.html'</span><span style="color: #339933;">,</span>
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'module'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'default'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'controller'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'html'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'action'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'handle'</span>
		<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>&nbsp;</p>
<p>2.HtmlController注册ZendEx_Plugin_Html插件,这里可以对uri进行处理</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * 静态化控制器
 * 
 * @author  yuehei
 * @package ex
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> HtmlController <span style="color: #000000; font-weight: bold;">extends</span> Core_Controller_Action
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> handleAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$requestUri</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_request<span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequestUri</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$requestUri</span> <span style="color: #339933;">=</span> <span style="color: #990000;">parse_url</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$requestUri</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$requestPath</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$requestUri</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'path'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// --- 通过条件定位对应的参数来静态化数据</span>
		<span style="color: #000088;">$module</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'default'</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$controller</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$action</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^\/index.html$/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$requestPath</span><span style="color: #339933;">,</span> <span style="color: #000088;">$rs</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$controller</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'index'</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$action</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'index'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #666666; font-style: italic;">// --- 文章页</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^\/file\/([\d]+)\/index\.html$/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$requestPath</span><span style="color: #339933;">,</span> <span style="color: #000088;">$rs</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rs</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$controller</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'file'</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$action</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'view'</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$controller</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$action</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">//$this-&gt;_showError('无法解析地址');</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_closeView<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_response<span style="color: #339933;">-&gt;</span><span style="color: #004000;">setHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Status'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'404 Not Found'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_forward<span style="color: #009900;">&#40;</span><span style="color: #000088;">$action</span><span style="color: #339933;">,</span> <span style="color: #000088;">$controller</span><span style="color: #339933;">,</span> <span style="color: #000088;">$module</span><span style="color: #339933;">,</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_closeView<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$filePath</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'_app'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'_www'</span><span style="color: #339933;">,</span> APP_PATH<span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$requestPath</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// --- 给更低的运行级别，在render之后运行</span>
		<span style="color: #000088;">$helperHtml</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ZendEx_Plugin_Html<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$helperHtml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFilePath</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filePath</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$helperHtml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setRequest</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_request<span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setResponse</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFrontController</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">registerPlugin</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$helperHtml</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://yuehei.37net.com/2011/12/zend-framework-plugin-html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>linode的东京机房太给力了</title>
		<link>http://yuehei.37net.com/2011/09/linode_tokyo_server_room/</link>
		<comments>http://yuehei.37net.com/2011/09/linode_tokyo_server_room/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 02:57:14 +0000</pubDate>
		<dc:creator>yuehei</dc:creator>
				<category><![CDATA[点滴]]></category>

		<guid isPermaLink="false">http://yuehei.37net.com/?p=174</guid>
		<description><![CDATA[昨天刚更换完，速度很给力，电信100以下，基本上可以媲美国内的服务器了。 换机房也很简单，提个ticket工作人员立马响应，二个小时左右换完，以后用联通的线路再也不用天天掉线了。鼓舞&#8230;]]></description>
			<content:encoded><![CDATA[<p><a href="http://yuehei.37net.com/wp-content/uploads/2011/09/QQ%E6%88%AA%E5%9B%BE20110922105004.jpg"><img class="alignnone size-medium wp-image-175" title="linode ping" src="http://yuehei.37net.com/wp-content/uploads/2011/09/QQ%E6%88%AA%E5%9B%BE20110922105004.jpg" alt="" /></a></p>
<p>昨天刚更换完，速度很给力，电信100以下，基本上可以媲美国内的服务器了。</p>
<p>换机房也很简单，提个ticket工作人员立马响应，二个小时左右换完，以后用联通的线路再也不用天天掉线了。鼓舞&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://yuehei.37net.com/2011/09/linode_tokyo_server_room/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FastDFS</title>
		<link>http://yuehei.37net.com/2011/07/fastdfs/</link>
		<comments>http://yuehei.37net.com/2011/07/fastdfs/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 03:53:18 +0000</pubDate>
		<dc:creator>yuehei</dc:creator>
				<category><![CDATA[platform]]></category>

		<guid isPermaLink="false">http://yuehei.37net.com/?p=169</guid>
		<description><![CDATA[fastdfs是一个分布式的文件存储系统， 项目主页：http://code.google.com/p/fastdfs/ 支持论坛：http://bbs.chinaunix.net/forum-240-1.html 测试了一下，发现很好用，优点： 1，简单：tracker做负载均衡，storage存储数据。 2，良好的横行和纵向扩展：增加group即可实现容量扩充，增加group内的storage即可实现性能扩充 3，节省成本：数据不分块存储，前端无须再加一层缓存，直接将storage当做web server来使用 4，良好的灾备：不需要raid，group内的storage存储相同的数据 5，持续的的更新，作者很用心 配置文件：http://bbs.chinaunix.net/thread-1941456-1-1.html]]></description>
			<content:encoded><![CDATA[<p>fastdfs是一个分布式的文件存储系统，</p>
<p>项目主页：http://code.google.com/p/fastdfs/</p>
<p>支持论坛：http://bbs.chinaunix.net/forum-240-1.html</p>
<p>测试了一下，发现很好用，优点：</p>
<p>1，简单：tracker做负载均衡，storage存储数据。</p>
<p>2，良好的横行和纵向扩展：增加group即可实现容量扩充，增加group内的storage即可实现性能扩充</p>
<p>3，节省成本：数据不分块存储，前端无须再加一层缓存，直接将storage当做web server来使用</p>
<p>4，良好的灾备：不需要raid，group内的storage存储相同的数据</p>
<p>5，持续的的更新，作者很用心</p>
<p>配置文件：http://bbs.chinaunix.net/thread-1941456-1-1.html</p>
]]></content:encoded>
			<wfw:commentRss>http://yuehei.37net.com/2011/07/fastdfs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>回望2010</title>
		<link>http://yuehei.37net.com/2011/01/2010/</link>
		<comments>http://yuehei.37net.com/2011/01/2010/#comments</comments>
		<pubDate>Fri, 31 Dec 2010 16:55:48 +0000</pubDate>
		<dc:creator>yuehei</dc:creator>
				<category><![CDATA[点滴]]></category>

		<guid isPermaLink="false">http://yuehei.37net.com/?p=144</guid>
		<description><![CDATA[1. 今天的年终总结是坚持，明年的计划仍然是坚持。 2. 从去年11.4开始跑步，这一年一直在跑，今早上秤81.7kg。 3. 三年又三年，这是第二个三年的结束，也是第三个三年的开始。上次我给自己画了一个大饼，结果变成了一烧饼，这次不画饼了，改成给自己吹个泡泡。 2010年再见，2011年你好。分享一首05年超级女生，就是李宇春那一届，有个叫赵静怡的选手唱了一首歌。  我的左手旁边是你的右手]]></description>
			<content:encoded><![CDATA[<p>1. 今天的年终总结是坚持，明年的计划仍然是坚持。<br />
2. 从去年11.4开始跑步，这一年一直在跑，今早上秤81.7kg。<br />
3. 三年又三年，这是第二个三年的结束，也是第三个三年的开始。上次我给自己画了一个大饼，结果变成了一烧饼，这次不画饼了，改成给自己吹个泡泡。</p>
<p>2010年再见，2011年你好。分享一首05年超级女生，就是李宇春那一届，有个叫赵静怡的选手唱了一首歌。</p>
<p> <a class="wpaudio" href="http://61.155.42.35/hi/uploads/audio/200803/16/1205666080-2614.mp3">我的左手旁边是你的右手</a></p>
]]></content:encoded>
			<wfw:commentRss>http://yuehei.37net.com/2011/01/2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://61.155.42.35/hi/uploads/audio/200803/16/1205666080-2614.mp3" length="4263865" type="audio/mpeg" />
		</item>
		<item>
		<title>旧的记事本</title>
		<link>http://yuehei.37net.com/2010/12/diary/</link>
		<comments>http://yuehei.37net.com/2010/12/diary/#comments</comments>
		<pubDate>Wed, 29 Dec 2010 13:43:48 +0000</pubDate>
		<dc:creator>yuehei</dc:creator>
				<category><![CDATA[点滴]]></category>

		<guid isPermaLink="false">http://yuehei.37net.com/?p=140</guid>
		<description><![CDATA[收拾衣服的时候，翻出了一本日记，从05年6月12号，一直写到07年1月20号，断断续续写了一年多。 随手翻翻，看着深浅不一的笔迹，依稀能回忆起当时的心境。 06/23/2005 正在看让我痴迷不已的诛仙，写了二页感想，这要是发到网上，那就是长评。 07/27/2005 非常想家 09/30/2005 连续好几篇都在写做游戏帮派论坛，做金山游戏推广员，怎么在学校里帖小广告，以及如何是被坑的悲惨故事。 12/05/2005 反思了自己的一些想法，以及看了《乱世铜炉》的感想。现在的我和5年前的我在一些价值观上仍然一致。 12/09/2005 第一次用java写程序的兴奋。 12/24/2005 平安夜让我回忆起了昔日的网友。 12/31/2005 年终的我发现又混过了一年 05/26/2006 确定电脑是我的饭碗 01/20/2007 年终总结：害怕 之后就开始工作了，刚工作时睡眠严重不足，就没有时间扯蛋了，整个日记也就断了。不写日记，我发现脑子里记的全是事，关于个人的感受已经模糊不清。现在又开始续写这本日记，不过留了一页空白，代表已逝去近四载的时光。]]></description>
			<content:encoded><![CDATA[<p>收拾衣服的时候，翻出了一本日记，从05年6月12号，一直写到07年1月20号，断断续续写了一年多。<br />
随手翻翻，看着深浅不一的笔迹，依稀能回忆起当时的心境。</p>
<p>06/23/2005   正在看让我痴迷不已的诛仙，写了二页感想，这要是发到网上，那就是长评。<br />
07/27/2005   非常想家<br />
09/30/2005   连续好几篇都在写做游戏帮派论坛，做金山游戏推广员，怎么在学校里帖小广告，以及如何是被坑的悲惨故事。<br />
12/05/2005   反思了自己的一些想法，以及看了《乱世铜炉》的感想。现在的我和5年前的我在一些价值观上仍然一致。<br />
12/09/2005   第一次用java写程序的兴奋。<br />
12/24/2005   平安夜让我回忆起了昔日的网友。<br />
12/31/2005   年终的我发现又混过了一年<br />
05/26/2006   确定电脑是我的饭碗<br />
01/20/2007   年终总结：害怕</p>
<p>之后就开始工作了，刚工作时睡眠严重不足，就没有时间扯蛋了，整个日记也就断了。不写日记，我发现脑子里记的全是事，关于个人的感受已经模糊不清。现在又开始续写这本日记，不过留了一页空白，代表已逝去近四载的时光。</p>
]]></content:encoded>
			<wfw:commentRss>http://yuehei.37net.com/2010/12/diary/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>心跳那几秒</title>
		<link>http://yuehei.37net.com/2010/12/dog/</link>
		<comments>http://yuehei.37net.com/2010/12/dog/#comments</comments>
		<pubDate>Tue, 28 Dec 2010 16:32:36 +0000</pubDate>
		<dc:creator>yuehei</dc:creator>
				<category><![CDATA[点滴]]></category>

		<guid isPermaLink="false">http://yuehei.37net.com/?p=136</guid>
		<description><![CDATA[晚上去吃饭，回来已经8点多了，折腾折腾，9点半左右才出去跑步，比平时晚了40多分钟。穿过像伊拉克一样的唐家岭废墟，沿着土井路跑，到达一个三叉路口，正常情况下我会沿着这条路一直跑到东北旺然后再原路返回。就在拐弯的时候，我看三十多米开外，有一条硕大的黑狗，慢悠悠的穿过马路，消失在黑暗里，当时没引起我警惕，因为一般情况下，这么大的狗都是有人带着的。 谁曾想，我刚跑到这个地方，这条连个绳子都没有的狗，突然从黑暗里窜了出来冲我狂叫，我当时第一反应是，这狗不会过来这狗不会过来，还没想完，这狗就冲我扑过来了。当时离的很近，我后退侧身闪过，手好像砸到什么，大拇指有点疼，当时第一感觉就是手破了手破了，要打狂犬疫苗了。大狗见没有扑到，就往后退了一点，冲我狂叫，我也面对着大狗戒备着，边对峙脚边往后退，当时不是很怕，感觉这条狗不像野狗，扑的时候不凶，也不快，可能是从家跑出来的，退到7，8米左右，这条狗又扑过来了，一个1米多高的狗快速冲人跑过来，还是非常恐怖的，我再次侧身闪过，幸好这时候来了一辆车，灯打过来时这狗就有点虚，一击不中，就又往后退，在那儿冲我吼，这时候已经离的比较远了，我也象征性在路边找了找砖头，可惜也没有找到，望了我一会儿，这狗就又消失在黑暗中了。没有找到砖头的我，思考了一下，决定这条路今天先不跑了，在路灯下看了看大拇指也没破皮，万幸。 这条路我跑了一年多，经常碰到流浪狗，尤其是唐家岭拆迁以后，更时不时的碰到拉帮结派5，6条在一起的狗群。有时候跑步也会被执著的狗追，但一般只要我停一下，这些狗就不敢靠近了，有些不长眼的狗，我要反过来追它们一下。但这次碰到这么大的，这么凶猛的，上来就扑的，还真是第一次，两个字总结：肝颤。明天早点，可不想再和这狗搏斗了。]]></description>
			<content:encoded><![CDATA[<p>      晚上去吃饭，回来已经8点多了，折腾折腾，9点半左右才出去跑步，比平时晚了40多分钟。穿过像伊拉克一样的唐家岭废墟，沿着土井路跑，到达一个三叉路口，正常情况下我会沿着这条路一直跑到东北旺然后再原路返回。就在拐弯的时候，我看三十多米开外，有一条硕大的黑狗，慢悠悠的穿过马路，消失在黑暗里，当时没引起我警惕，因为一般情况下，这么大的狗都是有人带着的。 </p>
<p>    谁曾想，我刚跑到这个地方，这条连个绳子都没有的狗，突然从黑暗里窜了出来冲我狂叫，我当时第一反应是，这狗不会过来这狗不会过来，还没想完，这狗就冲我扑过来了。当时离的很近，我后退侧身闪过，手好像砸到什么，大拇指有点疼，当时第一感觉就是手破了手破了，要打狂犬疫苗了。大狗见没有扑到，就往后退了一点，冲我狂叫，我也面对着大狗戒备着，边对峙脚边往后退，当时不是很怕，感觉这条狗不像野狗，扑的时候不凶，也不快，可能是从家跑出来的，退到7，8米左右，这条狗又扑过来了，一个1米多高的狗快速冲人跑过来，还是非常恐怖的，我再次侧身闪过，幸好这时候来了一辆车，灯打过来时这狗就有点虚，一击不中，就又往后退，在那儿冲我吼，这时候已经离的比较远了，我也象征性在路边找了找砖头，可惜也没有找到，望了我一会儿，这狗就又消失在黑暗中了。没有找到砖头的我，思考了一下，决定这条路今天先不跑了，在路灯下看了看大拇指也没破皮，万幸。</p>
<p>    这条路我跑了一年多，经常碰到流浪狗，尤其是唐家岭拆迁以后，更时不时的碰到拉帮结派5，6条在一起的狗群。有时候跑步也会被执著的狗追，但一般只要我停一下，这些狗就不敢靠近了，有些不长眼的狗，我要反过来追它们一下。但这次碰到这么大的，这么凶猛的，上来就扑的，还真是第一次，两个字总结：肝颤。明天早点，可不想再和这狗搏斗了。</p>
]]></content:encoded>
			<wfw:commentRss>http://yuehei.37net.com/2010/12/dog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nginx下wordpress的rewrite</title>
		<link>http://yuehei.37net.com/2010/10/nginx_wordpress_rewrite/</link>
		<comments>http://yuehei.37net.com/2010/10/nginx_wordpress_rewrite/#comments</comments>
		<pubDate>Fri, 08 Oct 2010 04:26:21 +0000</pubDate>
		<dc:creator>yuehei</dc:creator>
				<category><![CDATA[platform]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://yuehei.37net.com/?p=126</guid>
		<description><![CDATA[国庆前买了 linode 的VPS，算是edong撤走了，不用再去照相了，照相这种备案方式和以前BBS专项备案一样，没有什么操作性，迟早也要取消的。以前用edong vps，跑的是nginx+apache，这次直接换成nginx+spawn-fcgi。 # BEGIN WordPress &#60;IfModule mod_rewrite.c&#62; RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] &#60;/IfModule&#62; # END WordPress 上面是推荐的rewrite规则，但是这样规则会将不存在的图片,css等文件也都转发到index.php，这些文件应该报个404的。 #现在nginx上使用的rewrite server { server_name yuehei.37net.com; &#160; access_log /var/log/nginx/yuehei_37net_com_access.log main; error_log /var/log/nginx/yuehei_37net_com_error.log info; &#160; root /data/html/37net.com/yuehei; index index.html index.htm index.php; &#160; error_page 403 =200 /403.html; location = /403.html [...]]]></description>
			<content:encoded><![CDATA[<p>国庆前买了 <a href="http://www.linode.com/" target="_blank">linode</a> 的VPS，算是edong撤走了，不用再去照相了，照相这种备案方式和以前BBS专项备案一样，没有什么操作性，迟早也要取消的。以前用edong vps，跑的是nginx+apache，这次直接换成nginx+spawn-fcgi。</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;"># BEGIN WordPress</span>
&lt;<span style="color: #000000; font-weight:bold;">IfModule</span> mod_rewrite.c&gt;
<span style="color: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">On</span>
<span style="color: #00007f;">RewriteBase</span> /
<span style="color: #00007f;">RewriteCond</span> %{REQUEST_FILENAME} !-f
<span style="color: #00007f;">RewriteCond</span> %{REQUEST_FILENAME} !-d
<span style="color: #00007f;">RewriteRule</span> . /index.php [L]
&lt;/<span style="color: #000000; font-weight:bold;">IfModule</span>&gt;
<span style="color: #adadad; font-style: italic;"># END WordPress</span></pre></div></div>

<p>上面是推荐的rewrite规则，但是这样规则会将不存在的图片,css等文件也都转发到index.php，这些文件应该报个404的。</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">    <span style="color: #adadad; font-style: italic;">#现在nginx上使用的rewrite</span>
    server {
        server_name yuehei.37net.com;
&nbsp;
        access_log   /var/log/nginx/yuehei_37net_com_access.log main;
        error_log     /var/log/nginx/yuehei_37net_com_error.log info;
&nbsp;
        root  /data/html/37net.com/yuehei;
        index index.html index.htm index.php;
&nbsp;
        error_page  <span style="color: #ff0000;">403</span>  =<span style="color: #ff0000;">200</span> /<span style="color: #ff0000;">403</span>.html;
        location = /<span style="color: #ff0000;">403</span>.html {
            root /data/html;
        }
        error_page  <span style="color: #ff0000;">404</span>  =<span style="color: #ff0000;">200</span> /<span style="color: #ff0000;">404</span>.html;
        location = /<span style="color: #ff0000;">404</span>.html {
            root /data/html;
        }
&nbsp;
        location / {
            if (!-e $request_filename) {
                rewrite ^(.*)$ /index.php last;
                break;
            }
        }
&nbsp;
        location ~ \.(gif|jpg|jpeg|png|css|js)$ {
            expires 365d;
        }
&nbsp;
        location ~ \.php$ {
            <span style="color: #00007f;">include</span> /etc/nginx/fastcgi_params;
        }
    }</pre></div></div>

<p>测试一下: <a href="http://yuehei.37net.com/test_test.png">http://yuehei.37net.com/test_test.png</a>  报的是404了</p>
]]></content:encoded>
			<wfw:commentRss>http://yuehei.37net.com/2010/10/nginx_wordpress_rewrite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>5.2 – 6.5收藏</title>
		<link>http://yuehei.37net.com/2010/06/5-2_6-5/</link>
		<comments>http://yuehei.37net.com/2010/06/5-2_6-5/#comments</comments>
		<pubDate>Sat, 05 Jun 2010 05:12:51 +0000</pubDate>
		<dc:creator>yuehei</dc:creator>
				<category><![CDATA[收藏]]></category>

		<guid isPermaLink="false">http://yuehei.37net.com/?p=119</guid>
		<description><![CDATA[5公里，这段时间下雨，聚会，玩三国杀，跑的比较懈怠，85.5KG 1，EasyUI for jQuery 2，Persona——Web人物角色介绍 3，Web服务器压力测试工具http_load、webbench、ab、Siege使用教程 4，wxpython in action 非常详细的wxpython讲解，对我这种没有做GUI编程的人用处很大。刚看完到11章，准备写一个简单的使用SQLite的报表。]]></description>
			<content:encoded><![CDATA[<p>5公里，这段时间下雨，聚会，玩三国杀，跑的比较懈怠，85.5KG</p>
<p>1，<a href="http://shawphy.com/2010/05/easyui-for-jquery.html" target="_blanK">EasyUI for jQuery</a></p>
<p>2，<a href="http://www.alibuybuy.com/19338.html" target="_blanK">Persona——Web人物角色介绍</a></p>
<p>3，<a href="http://www.cnblogs.com/analyzer/articles/1735751.html" target="_blanK">Web服务器压力测试工具http_load、webbench、ab、Siege使用教程</a></p>
<p>4，<a href="http://wenku.baidu.com/view/5fcd2379168884868762d6d1.html" target="_blanK">wxpython in action</a>  非常详细的wxpython讲解，对我这种没有做GUI编程的人用处很大。刚看完到11章，准备写一个简单的使用SQLite的报表。</p>
]]></content:encoded>
			<wfw:commentRss>http://yuehei.37net.com/2010/06/5-2_6-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>看完《孤独六讲》</title>
		<link>http://yuehei.37net.com/2010/05/book_%e5%ad%a4%e7%8b%ac%e5%85%ad%e8%ae%b2/</link>
		<comments>http://yuehei.37net.com/2010/05/book_%e5%ad%a4%e7%8b%ac%e5%85%ad%e8%ae%b2/#comments</comments>
		<pubDate>Fri, 07 May 2010 18:34:37 +0000</pubDate>
		<dc:creator>yuehei</dc:creator>
				<category><![CDATA[读书]]></category>
		<category><![CDATA[孤独六讲]]></category>

		<guid isPermaLink="false">http://yuehei.37net.com/?p=116</guid>
		<description><![CDATA[这本书断断续续看了快了一个月，今天把最后几页看完。我打了四颗星，总体上来说还是不错，但是感觉太零碎，作者像是随手拾来，看不到严密的逻辑，感觉天马行空，这种书一般都不讨我喜。 很少人能坦然面对负面情绪，一出现就会想办法消除或者转移走，就像这个时代每个人都在强调自信，强调勇气，每个都在害怕自卑，害怕懦弱一样。人有七情六欲，交替博弈，是一个正反合的过程，一个再自信的人也有自卑的时候，一个再勇敢的人也有懦弱的时候，只要是个人它就无法摆脱这些情绪。不能坦然面对这些负面的情绪，就不能认识自我，更无法获得真正的自信，勇气。 这是一本很诚恳的书，很喜欢刚开始的一句：孤独没有什么不好，使孤独变得不好的，是害怕孤独。 这么晚了还不睡，主要是因为今天很点背，晚上取钱的时候，银行卡忘记拿出来了，一个杯具。]]></description>
			<content:encoded><![CDATA[<p><a href="http://book.douban.com/subject/4124727/"><img style="border: 0;" src="http://img2.douban.com/lpic/s4075572.jpg" alt="" /></a></p>
<p>这本书断断续续看了快了一个月，今天把最后几页看完。我打了四颗星，总体上来说还是不错，但是感觉太零碎，作者像是随手拾来，看不到严密的逻辑，感觉天马行空，这种书一般都不讨我喜。</p>
<p>很少人能坦然面对负面情绪，一出现就会想办法消除或者转移走，就像这个时代每个人都在强调自信，强调勇气，每个都在害怕自卑，害怕懦弱一样。人有七情六欲，交替博弈，是一个正反合的过程，一个再自信的人也有自卑的时候，一个再勇敢的人也有懦弱的时候，只要是个人它就无法摆脱这些情绪。不能坦然面对这些负面的情绪，就不能认识自我，更无法获得真正的自信，勇气。</p>
<p>这是一本很诚恳的书，很喜欢刚开始的一句：孤独没有什么不好，使孤独变得不好的，是害怕孤独。</p>
<p>这么晚了还不睡，主要是因为今天很点背，晚上取钱的时候，银行卡忘记拿出来了，一个杯具。</p>
]]></content:encoded>
			<wfw:commentRss>http://yuehei.37net.com/2010/05/book_%e5%ad%a4%e7%8b%ac%e5%85%ad%e8%ae%b2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WebGame 开发过程与备忘（一）前端基础框架的封装</title>
		<link>http://yuehei.37net.com/2010/05/webgame_development_1/</link>
		<comments>http://yuehei.37net.com/2010/05/webgame_development_1/#comments</comments>
		<pubDate>Thu, 06 May 2010 12:38:42 +0000</pubDate>
		<dc:creator>yuehei</dc:creator>
				<category><![CDATA[webgame]]></category>
		<category><![CDATA[开发]]></category>

		<guid isPermaLink="false">http://yuehei.37net.com/?p=107</guid>
		<description><![CDATA[这个webgame虽然还有bug，有一些功能要完善，界面也要重新更换，但基本上告一段落，我会一般修bug，一边做总结，这是这篇总结的第一章，算是一个备忘。 做这个项目之前，我有2年左右的PHP开发经验，对python有一些了解，javascript一般般，但用起来倒也得心应手。之前对webgame有一些了解，自己也玩过，也debug其中一些认为做的比较好的，这样也就不算陌生。 我的技术背景决定整个webgame是基于PHP+javascript来完成，为了更好的用户体验，我决定采用OPOA的形式。javascript项目有一个问题，就是连接保持，现在流行的comet方式，我都试了一遍，如果没有一个支持这一特性的web server配合的话，都不理想，最后还是使用了flash的socket，后面我会用专门一章节来讲。 其次，在做的过程中也走过一些弯路，比如刚开始，我过于强调所谓的性能，而把很多计算放到客户端来做，为了保证客户端时间正确，又把服务器的时间同步过来等等，做了一些无用功。javascript虽然功能很强大，但过于依赖javascript，限于个人的水平，会导致前端不可控，错误不可重现，bug无法排查，最后会被活活急死。 另一个重要的问题，就是整个后端返回的是数据还是html，我曾经debug一个知名的webgame，发现它整个后端都返回html，当时我不以为然，认为完全没有必要，所以我采用的就是返回json。现在看来其实两个都各有好处，返回html可以避免前端再进行处理（譬如非常烦人的数据组装），只要一个dom就可搞定。返回数据则可以减少数据量，加快响应速度，我现在采用的是数据+javascript模板的方式，javascript模板很少发现有网站在用，模板对于普通网站来说，可能弊大于利，但对于OPOA类的程序，好处显而易见的，配合延迟加载也可以减少一些弊端。 一般应用的过程是：前端 -&#62; 调用后端 -&#62; 处理结束 -&#62; 返回前端，这个过程webgame也有，但webgame有时候会回调前端，即： 前端 -&#62;  调用后端 -&#62; 处理结束 -&#62; 返回前端 -&#62; 再回调前端。 /* 一个例子：购买一个道具，就更新银两的显示。把JRun.loadBack看成是一个ajax的封装。 一般情况下代码会像下面这样写，但这样有一个弊端，不止买道具，其它很多地方(比如卖)也可能要更新银两显示， 难道每一次更新都要这样写吗？ */ JRun.loadBack&#40;'/goods/buy', &#123;goods_id: 1, num: 5&#125;, function&#40;data&#41; &#123; var status = data.status; if &#40;status == 1&#41; &#123; $&#40;'#role_tael'&#41;.html&#40;data.tael&#41;; &#125; &#125;&#41;; &#160; /* 下面的代码换了一种写法，所有更新银两的显示都调用了JRole.updateTael。 但是又有一个新的问题，买道具不一定非要银两，有可能是声望，购买成功以后也更新声望的显示， 这时候就需要扩展status，来告诉前端如何处理。 */ JRun.loadBack&#40;'/goods/buy', &#123;goods_id: 1, [...]]]></description>
			<content:encoded><![CDATA[<p>这个webgame虽然还有bug，有一些功能要完善，界面也要重新更换，但基本上告一段落，我会一般修bug，一边做总结，这是这篇总结的第一章，算是一个备忘。</p>
<p>做这个项目之前，我有2年左右的PHP开发经验，对python有一些了解，javascript一般般，但用起来倒也得心应手。之前对webgame有一些了解，自己也玩过，也debug其中一些认为做的比较好的，这样也就不算陌生。</p>
<p>我的技术背景决定整个webgame是基于PHP+javascript来完成，为了更好的用户体验，我决定采用OPOA的形式。javascript项目有一个问题，就是连接保持，现在流行的comet方式，我都试了一遍，如果没有一个支持这一特性的web server配合的话，都不理想，最后还是使用了flash的socket，后面我会用专门一章节来讲。</p>
<p>其次，在做的过程中也走过一些弯路，比如刚开始，我过于强调所谓的性能，而把很多计算放到客户端来做，为了保证客户端时间正确，又把服务器的时间同步过来等等，做了一些无用功。javascript虽然功能很强大，但过于依赖javascript，限于个人的水平，会导致前端不可控，错误不可重现，bug无法排查，最后会被活活急死。</p>
<p>另一个重要的问题，就是整个后端返回的是数据还是html，我曾经debug一个知名的webgame，发现它整个后端都返回html，当时我不以为然，认为完全没有必要，所以我采用的就是返回json。现在看来其实两个都各有好处，返回html可以避免前端再进行处理（譬如非常烦人的数据组装），只要一个dom就可搞定。返回数据则可以减少数据量，加快响应速度，我现在采用的是数据+javascript模板的方式，javascript模板很少发现有网站在用，模板对于普通网站来说，可能弊大于利，但对于OPOA类的程序，好处显而易见的，配合延迟加载也可以减少一些弊端。</p>
<p>一般应用的过程是：前端 -&gt; 调用后端 -&gt; 处理结束 -&gt; 返回前端，这个过程webgame也有，但webgame有时候会回调前端，即：<br />
前端 -&gt;  调用后端 -&gt; 处理结束 -&gt; 返回前端 -&gt; 再回调前端。</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*
一个例子：购买一个道具，就更新银两的显示。把JRun.loadBack看成是一个ajax的封装。
一般情况下代码会像下面这样写，但这样有一个弊端，不止买道具，其它很多地方(比如卖)也可能要更新银两显示，
难道每一次更新都要这样写吗？
*/</span>
JRun.<span style="color: #660066;">loadBack</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/goods/buy'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>goods_id<span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> num<span style="color: #339933;">:</span> <span style="color: #CC0000;">5</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066;">status</span> <span style="color: #339933;">=</span> data.<span style="color: #000066;">status</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">status</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#role_tael'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">tael</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">/*
下面的代码换了一种写法，所有更新银两的显示都调用了JRole.updateTael。
但是又有一个新的问题，买道具不一定非要银两，有可能是声望，购买成功以后也更新声望的显示，
这时候就需要扩展status，来告诉前端如何处理。
*/</span>
JRun.<span style="color: #660066;">loadBack</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/goods/buy'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>goods_id<span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> num<span style="color: #339933;">:</span> <span style="color: #CC0000;">5</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066;">status</span> <span style="color: #339933;">=</span> data.<span style="color: #000066;">status</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">status</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        JRole.<span style="color: #660066;">updateTael</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">tael</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">status</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	JRole.<span style="color: #660066;">updateRepute</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">repute</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> JRole <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    updateTael<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>tael<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#role_tael'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>tael<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    updateRepute<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>repute<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#role_repute'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>repute<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>随着要处理的类型的增多，status会越来越多，整个前端会很臃肿，而且会越来越不可控。如何让后端更自由的调用前端？有一些webgame返回的是html，里面内嵌javascript，这种方式并不推荐。可以采用格式化的返回数据来解决这个问题。</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// 前端调用</span>
JRun.<span style="color: #660066;">loadBack</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/goods/buy'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>goods_id<span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> num<span style="color: #339933;">:</span> <span style="color: #CC0000;">5</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// goods/buy返回数据格式</span>
<span style="color: #009900;">&#123;</span><span style="color: #000066;">status</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> data<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>tael<span style="color: #339933;">:</span> <span style="color: #CC0000;">5</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> callBack<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;JRole.updateTael(data.tael);&quot;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>这样就清晰简单多了，前端只需一行代码。服务器处理完成以后，自定义callBack作为返回内容，前端会自动调用并将数据传入。只要对JRun.loadBack进行简单的封闭，让它识别callBack的内容。后端对前端的可控性会降低前端的代码量，同时也可应对复杂的交互。</p>
<p>这样的前端设计基本上能满足我目前的应用。另外如果我能在开发早期注意到问题，完全可以在实现控制(JRun.loadBack)，模型(后端PHP)，模板(javascript渲染)的分离。</p>
]]></content:encoded>
			<wfw:commentRss>http://yuehei.37net.com/2010/05/webgame_development_1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

