<?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>Verdana Experiments</title>
	<atom:link href="http://www.phpvim.net/feed" rel="self" type="application/rss+xml" />
	<link>http://www.phpvim.net</link>
	<description>{coding, life, lonely}</description>
	<lastBuildDate>Wed, 04 Jan 2012 13:04:32 +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>Windows 中编译 PHP5.4 + xdebug</title>
		<link>http://www.phpvim.net/web/php/build-php5-4-and-xdebug-on-win32.html</link>
		<comments>http://www.phpvim.net/web/php/build-php5-4-and-xdebug-on-win32.html#comments</comments>
		<pubDate>Sun, 18 Dec 2011 12:28:26 +0000</pubDate>
		<dc:creator>Verdana Mu</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[xdebug]]></category>

		<guid isPermaLink="false">http://www.phpvim.net/?p=570</guid>
		<description><![CDATA[实际上我最终目的是编译得到支持 PHP5.4 的 php_xdebug.dll，而在此之前，成功编译 PHP5.4 是必须的。 编译环境以及相关软件包： Microsoft Visual C++ 2008 Express Edition with SP1 Windows SDK 6.1 PHP SDK Binary Tools Dependable libs PHP5.4 Sources Xdebug 2.2.0-dev 如果你需要的是 VC6 的编译环境，那么你需要安装 Visual C++ 6.0，而 SDK 则需要换成: Windows Server 2003 PSDK 编译过程： 准备好咖啡、可乐，做好准备，可能要折腾数小时&#8230; 安装 VC++ 2008 以及 Windows SDK 6.1 建立如下目录： D:\php-sdk D:\php-sdk\php54dev D:\php-sdk\pecl 解压 php-sdk-binary-tools-20110915.zip [...]]]></description>
			<content:encoded><![CDATA[<p>实际上我最终目的是编译得到支持 PHP5.4 的 php_xdebug.dll，而在此之前，成功编译 PHP5.4 是必须的。</p>
<p><strong>编译环境以及相关软件包：</strong></p>
<ol>
<li><a href="http://www.microsoft.com/visualstudio/en-us/products/2008-editions/express" target="_blank">Microsoft Visual C++ 2008 Express Edition with SP1</a></li>
<li><a href="http://www.microsoft.com/download/en/details.aspx?id=11310#Overview" target="_blank">Windows SDK 6.1</a></li>
<li><a href="http://windows.php.net/downloads/php-sdk" target="_blank">PHP SDK Binary Tools</a></li>
<li><a href="http://windows.php.net/downloads/php-sdk" target="_blank">Dependable libs</a></li>
<li><a href="http://qa.php.net" target="_blank">PHP5.4 Sources</a></li>
<li><a href="https://github.com/derickr/xdebug" target="_blank">Xdebug 2.2.0-dev</a></li>
</ol>
<p>如果你需要的是 VC6 的编译环境，那么你需要安装 Visual C++ 6.0，而 SDK 则需要换成:<br />
<a href="http://www.microsoft.com/download/en/details.aspx?id=22668" target="_blank">Windows Server 2003 PSDK</a></p>
<p><strong>编译过程：</strong></p>
<p>准备好咖啡、可乐，做好准备，可能要折腾数小时&#8230;</p>
<p>安装 VC++ 2008 以及 Windows SDK 6.1</p>
<p>建立如下目录：<br />
D:\php-sdk<br />
D:\php-sdk\php54dev<br />
D:\php-sdk\pecl</p>
<p>解压 php-sdk-binary-tools-20110915.zip 中的所有文件至 D:\php-sdk<br />
提取 deps-5.4-vc9-x86.7z 中的 deps 目录至 D:\php-sdk\php54dev<br />
解压 php5.4 源码至 D:\php-sdk\php54dev，目录名任取，比如 php-5.4.0RC3<br />
xdebug 的源码放到 D:\php-sdk\pecl\xdebug</p>
<p>最终的目录结构大概是这样子的：</p>
<pre lang="dos" line=1>
D:\php-sdk>tree D:\php-sdk
Folder PATH listing for volume DISK_VOL2
Volume serial number is 0C74-AD73
D:\PHP-SDK
├───bin
├───php54dev
│   ├───deps
│   │   ├───bin
│   │   ├───include
│   │   ├───lib
│   │   └───sybase
│   ├───pecl
│   │   └───xdebug
│   └───php-5.4.0RC3
├───script
└───share
</pre>
<p><br/></p>
<p>打开 Windows SDK CMD Shell，执行：setenv /x86 /xp /release，如果你是64位系统，那么这个命令是必须的，不要试图把参数改成 /x64，否则后续的 make 阶段，你会看到成千上万条 WARNING &#8230;</p>
<p>设定 PATH：set PATH=D:\php-sdk\bin;%PATH%</p>
<p>切换 SHELL 目录至 D:\php-sdk\php54dev\php-5.4.0RC3>，执行 buildconf 生成 configure 脚本：</p>
<pre lang="dos" line=1>
D:\php-sdk\php54dev\php-5.4.0RC3>buildconf
Rebuilding configure.js
Now run 'configure --help'
D:\php-sdk\php54dev\php-5.4.0RC3>
</pre>
<p><br/></p>
<p>执行 configure 生成 Make 脚本，可以查看 configure &#8211;help 以获取更多编译选项：</p>
<pre lang="dos" line=1 style="word-break:break-all;white-space: normal">
D:\php-sdk\php54dev\php-5.4.0RC3>configure --disable-snapshot-build --disable-debug-pack --disable-ipv6 --disable-zts --disable-isapi --disable-nsapi --without-t1lib --without-mssql --without-pdo-mssql --without-pi3web --without-enchant --enable-com-dotnet --with-mcrypt=static --disable-static-analyze --with-xdebug=shared
</pre>
<p>这里我使用了 &#8211;disable-snapshot-build 关掉了 snapshot 模式，因为这个命令会强制开启许多对我来说无用的选项，比如 aolserver，apache sapi 之类的，最后我加上了 &#8211;with-xdebug=shared，在使用这个选项之前最好确认 xdebug 源码的位置正确，如果没什么问题的话，buildconf 之后，在 configure &#8211;help 中你可以看到这个选项，shared 表示编译成动态链接库。</p>
<p>如果你要编译其它的 pecl 扩展（比如 apc，bcompiler 等），只需要相关的源码下载放到 pecl 目录，重新执行 buildconf 即可。</p>
<p>若 configure 无问题，最后执行 nmake 开始编译过程，Good Luck! <img src='http://www.phpvim.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>最后一步 nmake snap，组织所有编译好的文件的目录结构（也就是你平时下载的 PHP 二进制包的结构），并用 zip 打包。</p>
<p>最终生成的文件位置：D:\php-sdk\php54dev\php-5.4.0RC3\Release(_TS)</p>
<p><strong>错误处理：</strong><br />
nmake 过程中会产生很多的 Warning，只要不中断，那么就无视好了。</p>
<p>关于 calendar.c 和 jewish.c 的编码问题：</p>
<pre lang="dos" line=1 style="word-break:break-word;white-space: pre-wrap">
ext\calendar\calendar.c : warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss
dow.c
easter.c
french.c
gregor.c
jewish.c
ext\calendar\jewish.c : warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss
ext\calendar\jewish.c(324) : error C2001: newline in constant
ext\calendar\jewish.c(325) : error C2001: newline in constant
ext\calendar\jewish.c(326) : error C2001: newline in constant
ext\calendar\jewish.c(327) : error C2001: newline in constant
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\Bin\cl.exe"' : return code '0x2'
Stop.
</pre>
<p>这两个文件使用的是 ANSI 编码，包含有一些西文的特殊字符，GBK 字符集中不存在。<br />
可用 editplus 打开，编码选择：West European (Windows)，另存为 UTF-8。</p>
<p><strong>参考资料：</strong><br />
<a href="https://wiki.php.net/internals/windows/stepbystepbuild" target="_blank">https://wiki.php.net/internals/windows/stepbystepbuild</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpvim.net/web/php/build-php5-4-and-xdebug-on-win32.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>修正 Vim(Mac) 有时无法正确提交 Git Commit Message 的问题</title>
		<link>http://www.phpvim.net/app/vim/fix-issue-there-was-a-problem-with-editor-vim.html</link>
		<comments>http://www.phpvim.net/app/vim/fix-issue-there-was-a-problem-with-editor-vim.html#comments</comments>
		<pubDate>Wed, 14 Jul 2010 19:04:30 +0000</pubDate>
		<dc:creator>Verdana Mu</dc:creator>
				<category><![CDATA[Vim]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Macintosh]]></category>

		<guid isPermaLink="false">http://www.phpvim.net/?p=561</guid>
		<description><![CDATA[和 Subversion 一样，Git 也可以为 Commit Message 设置一个默认的编辑器，命令如下： 1 $ git config --global core.editor vim 不过我在 Mac OS X 系统使用 Git 的过程中，偶尔会遇到如下的情况： 1 2 3 4 5 6 7 *** Commands *** 1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: help What now&#62; q Bye. error: There was [...]]]></description>
			<content:encoded><![CDATA[<p>和 Subversion 一样，Git 也可以为 Commit Message 设置一个默认的编辑器，命令如下：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">git</span> config <span style="color: #660033;">--global</span> core.editor <span style="color: #c20cb9; font-weight: bold;">vim</span></pre></td></tr></table></div>

<p>不过我在 Mac OS X 系统使用 Git 的过程中，偶尔会遇到如下的情况：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">***</span> Commands <span style="color: #000000; font-weight: bold;">***</span>
  <span style="color: #000000;">1</span>: status	  <span style="color: #000000;">2</span>: update	  <span style="color: #000000;">3</span>: revert	  <span style="color: #000000;">4</span>: add untracked
  <span style="color: #000000;">5</span>: <span style="color: #c20cb9; font-weight: bold;">patch</span>	  <span style="color: #000000;">6</span>: <span style="color: #c20cb9; font-weight: bold;">diff</span>	  <span style="color: #000000;">7</span>: quit	  <span style="color: #000000;">8</span>: <span style="color: #7a0874; font-weight: bold;">help</span>
What now<span style="color: #000000; font-weight: bold;">&gt;</span> q
Bye.
error: There was a problem with the editor <span style="color: #ff0000;">'vim'</span>.
Please supply the message using either <span style="color: #660033;">-m</span> or <span style="color: #660033;">-F</span> option.</pre></td></tr></table></div>

<p>这种情况基本上都是出现在我打错字的时候，开始以为是输入法引起的 Vim 状态异常，不过出现的次数多了才慢慢发现一个规律——如果在 Vim 中编辑文本时因为按键失误出现类似这样：<em>E492: Not an editor command&#8230;</em> 的错误信息时，必然无法提交。</p>
<p>查了一下 <a href="http://progit.org/book/ch7-3.html">ProGit 的文档</a>后了解到：如果 Git 的 Commit Hooks 检测到脚本的返回非零状态码的话（Non-Zero Code，表示有错误发生），会阻止本次提交。到这里问题就比较清晰了，显然是 Vim 非正常退出返回了 Non-Zero Code。</p>
<p>为了验证猜测，我作了如下操作，打开终端 Vim，随便输入几个无效指令，造成 Exxx 之类的错误，然后立刻使用 :q 退出，观察返回値，结果：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">verdana<span style="color: #000000; font-weight: bold;">@</span>phpvim:~ <span style="color: #666666; font-style: italic;"># vim</span>
verdana<span style="color: #000000; font-weight: bold;">@</span>phpvim:~ <span style="color: #666666; font-style: italic;"># echo $?</span>
<span style="color: #000000;">1</span></pre></td></tr></table></div>

<p> <img src='http://www.phpvim.net/wp-includes/images/smilies/icon_rolleyes.gif' alt=':roll:' class='wp-smiley' />  果然是这样呢！</p>
<p>后来在 <a href="http://groups.google.com/group/vim_mac/browse_thread/thread/0d33e2f2130867b0">Google Group: vim_mac</a> 这个帖子中找到了解决的办法，就是使用完整的 Vim 路径—— /usr/bin/vim :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">git</span> config <span style="color: #660033;">--global</span> core.editor <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">vim</span></pre></td></tr></table></div>

<p>不太清楚 Mac OS X 中 Vim 为何会有这种问题，Bram 老大亲自现身作了解释：</p>
<blockquote><p>Vim 在遇到 Exx Error 时返回 Non-Zero code 是为了兼容 Posix，不过这种情况应该只会出现在使用 Ex Mode 时，Normal/Insert Mode 是不会这样的。</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.phpvim.net/app/vim/fix-issue-there-was-a-problem-with-editor-vim.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vim color scheme: molokai</title>
		<link>http://www.phpvim.net/app/vim/vim-color-scheme-molokai.html</link>
		<comments>http://www.phpvim.net/app/vim/vim-color-scheme-molokai.html#comments</comments>
		<pubDate>Wed, 07 Jul 2010 11:38:19 +0000</pubDate>
		<dc:creator>Verdana Mu</dc:creator>
				<category><![CDATA[Vim]]></category>

		<guid isPermaLink="false">http://www.phpvim.net/?p=554</guid>
		<description><![CDATA[今天在 vim.org 的脚本库里面闲逛的时候，无意中看到了这个颜色主题。暗色系主题，颜色运用很鲜艳，看起来很养眼，美中不足的是 comment 颜色稍微偏暗了一些，看着不是很清楚，可以打开 molokai.vim 修改一下 hi Comment &#8230; 改成亮一点的颜色&#8230; 下载地址： http://www.vim.org/scripts/script.php?script_id=2340]]></description>
			<content:encoded><![CDATA[<p>今天在 <a href="http://www.vim.org">vim.org</a> 的脚本库里面闲逛的时候，无意中看到了这个颜色主题。暗色系主题，颜色运用很鲜艳，看起来很养眼，美中不足的是 comment 颜色稍微偏暗了一些，看着不是很清楚，可以打开 molokai.vim 修改一下 hi Comment &#8230; 改成亮一点的颜色&#8230;</p>
<p><a href="http://www.phpvim.net/wp-content/uploads/2010/07/molokai-php.png" onclick="return hs.expand(this);" class="highslide-image"><img src="http://www.phpvim.net/wp-content/uploads/2010/07/molokai-php-300x179.png" alt="Vim colorscheme - molokai (php)" title="Click to enlarge" /></a></p>
<p><a href="http://www.phpvim.net/wp-content/uploads/2010/07/molokai-vim.png" onclick="return hs.expand(this);" class="highslide-image"><img src="http://www.phpvim.net/wp-content/uploads/2010/07/molokai-vim-300x254.png" alt="Vim colorscheme - molokai (vim)" title="Click to enlarge" /></a></p>
<p>下载地址：<br />
<a href="http://www.vim.org/scripts/script.php?script_id=2340">http://www.vim.org/scripts/script.php?script_id=2340</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpvim.net/app/vim/vim-color-scheme-molokai.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vim 中离开 Insert 模式的快捷键</title>
		<link>http://www.phpvim.net/app/vim/shortcut-for-leaving-insert-mode-vim.html</link>
		<comments>http://www.phpvim.net/app/vim/shortcut-for-leaving-insert-mode-vim.html#comments</comments>
		<pubDate>Tue, 06 Jul 2010 19:29:46 +0000</pubDate>
		<dc:creator>Verdana Mu</dc:creator>
				<category><![CDATA[Vim]]></category>

		<guid isPermaLink="false">http://www.phpvim.net/?p=551</guid>
		<description><![CDATA[Vim 中码字，在 Insert/Normal 两种模式中频繁切换是无可避免的。那么如何快速在两种模式中切换，显然影响到我们的操作效率。 这里有三个快捷键可以选择： ESC, CTRL+C, CTRL+[ 从便捷性上来看，CTRL+C 貌似是最顺手的，CTRL+[ 次之（需要两只手），ESC 最麻烦了，左手需要离开键盘的主要操作区域。 从功能上来看，ESC 等同于 CTRL+[，两者是完全一样的。CTRL+C 则稍稍不同，区别在于它不会自动展开 abbreviations，也不会触发 InsertLeave 事件。在某些些情况下，这可能会造成一点小小的困扰，比如下面的配置。 1 2 3 4 &#34; 当切换 Insert/Normal 模式时，动态修改状态栏颜色 hi StatusLine guifg=#FBFAFB guibg=#755939 gui=bold autocmd InsertEnter * hi statusline guifg=#FBFAFB guibg=#44507F gui=bold autocmd InsertLeave * hi statusline guifg=#FBFAFB guibg=#755939 gui=bold 如果使用 CTRL+C，那么上面最后一行配置就不起作用了。 好在 Vim 可以重新定义按键： 1 2 [...]]]></description>
			<content:encoded><![CDATA[<p>Vim 中码字，在 Insert/Normal 两种模式中频繁切换是无可避免的。那么如何快速在两种模式中切换，显然影响到我们的操作效率。</p>
<p>这里有三个快捷键可以选择： <strong>ESC</strong>, <strong>CTRL+C</strong>, <strong>CTRL+[</strong></p>
<p>从便捷性上来看，CTRL+C 貌似是最顺手的，CTRL+[ 次之（需要两只手），ESC 最麻烦了，左手需要离开键盘的主要操作区域。</p>
<p>从功能上来看，ESC 等同于 CTRL+[，两者是完全一样的。CTRL+C 则稍稍不同，区别在于它不会自动展开 abbreviations，也不会触发 InsertLeave 事件。在某些些情况下，这可能会造成一点小小的困扰，比如下面的配置。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;">&quot; 当切换 Insert/Normal 模式时，动态修改状态栏颜色</span>
<span style="color: #804040;">hi</span> StatusLine guifg=#FBFAFB  guibg=#<span style="color: #000000; font-weight:bold;">755939</span>  gui=bold
<span style="color: #804040;">autocmd</span> <span style="color: #25BB4D;">InsertEnter</span> <span style="color: #000000;">*</span> <span style="color: #804040;">hi</span> <span style="color: #668080;">statusline</span> guifg=#FBFAFB guibg=#44507F gui=bold
<span style="color: #804040;">autocmd</span> <span style="color: #25BB4D;">InsertLeave</span> <span style="color: #000000;">*</span> <span style="color: #804040;">hi</span> <span style="color: #668080;">statusline</span> guifg=#FBFAFB guibg=#<span style="color: #000000; font-weight:bold;">755939</span> gui=bold</pre></td></tr></table></div>

<p>如果使用 CTRL+C，那么上面最后一行配置就不起作用了。</p>
<p>好在 Vim 可以重新定义按键：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="vim" style="font-family:monospace;">inoremap <span style="color: #000000;">&lt;</span>C<span style="color: #000000;">-</span>c<span style="color: #000000;">&gt;</span> <span style="color: #000000;">&lt;</span>ESC<span style="color: #000000;">&gt;</span><span style="color: #adadad; font-style: italic;">
&nbsp;
&quot; 或者作一些小小的改进</span>
inoremap <span style="color: #000000;">&lt;</span>C<span style="color: #000000;">-</span>c<span style="color: #000000;">&gt;</span> <span style="color: #000000;">&lt;</span>ESC<span style="color: #000000;">&gt;</span>`<span style="color: #000000;">^</span></pre></td></tr></table></div>

<p>abbr 依然不会自动展开，实际上这个不是问题，可以使用空格、回车，CTRL+]等等替代，重要的是 InsertLeave Event 回来了。</p>
<p>
<h2>光标的漂移</h2>
</p>
<p>默认的情况下，当你按 &lt;ESC&gt; 返回 Normal 模式时，光标会向左边移动一个字符，上面的第二个映射命令中添加了 `^，这样就能让光标保持原来的位置，不再乱跑了。</p>
<p>更多相关的知识请参考（准备好梯子） <img src='http://www.phpvim.net/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' />  ：<br />
<a href="http://vim.wikia.com/wiki/Avoid_the_escape_key">http://vim.wikia.com/wiki/Avoid_the_escape_key</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpvim.net/app/vim/shortcut-for-leaving-insert-mode-vim.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sweet Home Alabama</title>
		<link>http://www.phpvim.net/music/sweet-home-alabama.html</link>
		<comments>http://www.phpvim.net/music/sweet-home-alabama.html#comments</comments>
		<pubDate>Sun, 27 Jun 2010 09:10:50 +0000</pubDate>
		<dc:creator>Verdana Mu</dc:creator>
				<category><![CDATA[Music]]></category>

		<guid isPermaLink="false">http://www.phpvim.net/?p=548</guid>
		<description><![CDATA[找不到《空中监狱》的版本 How do i live，只好听听原版了~ PS: 看来无法引用 Google Music 的地址，隔了一天发现地址变了]]></description>
			<content:encoded><![CDATA[<p>找不到《空中监狱》的版本 How do i live，只好听听原版了~</p>
<p><a href="http://www.phpvim.net/wp-content/uploads/2010/06/Lynyrd-Skynyrd_-All-Time-Greatest-Hits.jpg" onclick="return hs.expand(this, {captionId:'caption_1277629748356'});" class="highslide-image"><img src="http://www.phpvim.net/wp-content/uploads/2010/06/Lynyrd-Skynyrd_-All-Time-Greatest-Hits-300x300.jpg" alt="image" title="Click to enlarge" /></a></p>
<p>PS: 看来无法引用 Google Music 的地址，隔了一天发现地址变了 <img src='http://www.phpvim.net/wp-includes/images/smilies/icon_idea.gif' alt=':idea:' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpvim.net/music/sweet-home-alabama.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>让 Bash 自动完成忽略大小写</title>
		<link>http://www.phpvim.net/os/mac/auto-complete-ignoring-case-in-bash.html</link>
		<comments>http://www.phpvim.net/os/mac/auto-complete-ignoring-case-in-bash.html#comments</comments>
		<pubDate>Mon, 21 Jun 2010 19:12:48 +0000</pubDate>
		<dc:creator>Verdana Mu</dc:creator>
				<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Macintosh]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.phpvim.net/?p=546</guid>
		<description><![CDATA[大多数人在使用 Bash 时，都会对其进行改造，因为默认的设置真的好难用～ 参考以下 ~/.inputrc 设置： 1 2 3 4 5 6 7 8 9 # do not show hidden files in the list set match-hidden-files off &#160; # auto complete ignoring case set show-all-if-ambiguous on set completion-ignore-case on &#34;\ep&#34;: history-search-backward &#34;\e[A&#34;: history-search-backward &#34;\e[B&#34;: history-search-forward 默认情况下，按下两次 &#60;tab&#62; 才会出现提示，show-all-if-ambiguous 开启后，只需要一次了。 关掉 match-hidden-files 不显示隐藏文件，特比是当你在 Home 目录时，你会觉得眼前好干净。 开启 [...]]]></description>
			<content:encoded><![CDATA[<p>大多数人在使用 Bash 时，都会对其进行改造，因为默认的设置真的好难用～</p>
<p>参考以下 ~/.inputrc 设置：</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="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># do not show hidden files in the list</span>
<span style="color: #000000; font-weight: bold;">set</span> match-hidden-files off
&nbsp;
<span style="color: #666666; font-style: italic;"># auto complete ignoring case</span>
<span style="color: #000000; font-weight: bold;">set</span> show-all-if-ambiguous on
<span style="color: #000000; font-weight: bold;">set</span> completion-ignore-case on
<span style="color: #ff0000;">&quot;\ep&quot;</span>: history-search-backward
<span style="color: #ff0000;">&quot;\e[A&quot;</span>: history-search-backward
<span style="color: #ff0000;">&quot;\e[B&quot;</span>: history-search-forward</pre></td></tr></table></div>

<p>默认情况下，按下两次 &lt;tab&gt; 才会出现提示，show-all-if-ambiguous 开启后，只需要一次了。<br />
关掉 match-hidden-files 不显示隐藏文件，特比是当你在 Home 目录时，你会觉得眼前好干净。<br />
开启 completion-ignore-case 忽略大小写，写 PHP 时我估计大约 1/4 的按键都是 shift + 4，该死的美元符号！Shell 命令，我不想再和大写字母纠缠了，让 &lt;tab&gt; 搞定好了。<br />
history-search-*，输入几个字母，按上下箭头，搜索你的历史命令。</p>
<p>更多 Bash 定制请参考：<br />
<a href="https://wiki.ubuntu.com/Spec/EnhancedBash">https://wiki.ubuntu.com/Spec/EnhancedBash</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpvim.net/os/mac/auto-complete-ignoring-case-in-bash.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>在 Shell 提示符中显示 Git 分支名称</title>
		<link>http://www.phpvim.net/os/mac/git-branch-in-bash-prompt.html</link>
		<comments>http://www.phpvim.net/os/mac/git-branch-in-bash-prompt.html#comments</comments>
		<pubDate>Mon, 21 Jun 2010 14:26:06 +0000</pubDate>
		<dc:creator>Verdana Mu</dc:creator>
				<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Macintosh]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://www.phpvim.net/?p=541</guid>
		<description><![CDATA[Git 的好处之一就是把代码的分支管理变成了一件极其便捷的事情，分支只保留差异，不用复制任何文件，不用连接网络，快速创建，用完即删。Git 分支与项目的复杂程度无关，不管你的项目多么复杂，创建 Git 分支永远都是瞬间的事情。同时，因为保留了父类分支的信息，所以分支的合并也变得异常简单。 当在一个项目中频繁使用多个分支时，可以使用 git status 命令查询自己现在正工作在哪个分支下面，不过难免有脑子发昏的时候，忘记自己在哪个分支下面，因而发生误操作之类的杯具。 那么把分支显示在 Shell 提示符中无疑方便了很多，再也不需要频繁的使用 git status 命令了&#8230; 实现原理很简单，大体就是查询当前目录下面的 Git 分支名称，然后嵌入到 PS1 变量中。那么，Git 分支名称可以通过下面的脚本轻松的获得： git branch --no-color 2&#62; /dev/null &#124; sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' 把上面的脚本封装到函数中，修改 PS1 变量，嵌入函数&#8230; 大体是这样。但是这样也意味着一个问题，就是每次 shell 活动（比如切换目录，甚至只是敲下回车）都会执行一次 git &#8230; sed 命令，这样每次都启动2个进程，实在是有些不爽。 好在，可以使用另外一种方式来获取 Git 分支名称，在每个 Git 项目中，都有一个 .git 目录，这个目录下面有个叫做 HEAD 的文件，里面包含的当前分支的路径信息： ref: refs/heads/BRANCH-NAME 我们只要读取这个文件，然后再和对应的路径互相匹配一下就知道正确地分支名称了。不要只是简单的从 [...]]]></description>
			<content:encoded><![CDATA[<p>Git 的好处之一就是把代码的分支管理变成了一件极其便捷的事情，分支只保留差异，不用复制任何文件，不用连接网络，快速创建，用完即删。Git 分支与项目的复杂程度无关，不管你的项目多么复杂，创建 Git 分支永远都是瞬间的事情。同时，因为保留了父类分支的信息，所以分支的合并也变得异常简单。</p>
<p>当在一个项目中频繁使用多个分支时，可以使用 git status 命令查询自己现在正工作在哪个分支下面，不过难免有脑子发昏的时候，忘记自己在哪个分支下面，因而发生误操作之类的杯具。</p>
<p>那么把分支显示在 Shell 提示符中无疑方便了很多，再也不需要频繁的使用 git status 命令了&#8230;</p>
<p>实现原理很简单，大体就是查询当前目录下面的 Git 分支名称，然后嵌入到 PS1 变量中。那么，Git 分支名称可以通过下面的脚本轻松的获得：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> branch <span style="color: #660033;">--no-color</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'/^[^*]/d'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/* \(.*\)/(\1)/'</span></pre></div></div>

<p>把上面的脚本封装到函数中，修改 PS1 变量，嵌入函数&#8230; 大体是这样。但是这样也意味着一个问题，就是每次 shell 活动（比如切换目录，甚至只是敲下回车）都会执行一次 git &#8230; sed 命令，这样每次都启动2个进程，实在是有些不爽。</p>
<p>好在，可以使用另外一种方式来获取 Git 分支名称，在每个 Git 项目中，都有一个 .git 目录，这个目录下面有个叫做 HEAD 的文件，里面包含的当前分支的路径信息：</p>

<div class="wp_syntax"><div class="code"><pre class="git" style="font-family:monospace;">ref: refs/heads/BRANCH-NAME</pre></div></div>

<p>我们只要读取这个文件，然后再和对应的路径互相匹配一下就知道正确地分支名称了。不要只是简单的从 HEAD 内容中拆分出最后的 <em>BRANCH-NAME</em>，因为它不一定是正确地。</p>
<p>以下是 <a href="http://aaroncrane.co.uk/2009/03/git_branch_prompt/">Aaron Crane</a> 的实现方式：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">## Parses out the branch name from .git/HEAD:</span>
find_git_branch <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #007800;">dir</span>=. <span style="color: #c20cb9; font-weight: bold;">head</span>
    <span style="color: #000000; font-weight: bold;">until</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$dir</span>&quot;</span> <span style="color: #660033;">-ef</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$dir</span>/.git/HEAD&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
            <span style="color: #007800;">head</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$dir</span>/.git/HEAD&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$head</span> = ref:\ refs<span style="color: #000000; font-weight: bold;">/</span>heads<span style="color: #000000; font-weight: bold;">/*</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
                <span style="color: #007800;">git_branch</span>=<span style="color: #ff0000;">&quot; → <span style="color: #007800;">${head#*/*/}</span>&quot;</span>
            <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$head</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">''</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
                <span style="color: #007800;">git_branch</span>=<span style="color: #ff0000;">&quot; → (detached)&quot;</span>
            <span style="color: #000000; font-weight: bold;">else</span>
                <span style="color: #007800;">git_branch</span>=<span style="color: #ff0000;">&quot; → (unknow)&quot;</span>
            <span style="color: #000000; font-weight: bold;">fi</span>
            <span style="color: #7a0874; font-weight: bold;">return</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
        <span style="color: #007800;">dir</span>=<span style="color: #ff0000;">&quot;../<span style="color: #007800;">$dir</span>&quot;</span>
    <span style="color: #000000; font-weight: bold;">done</span>
    <span style="color: #007800;">git_branch</span>=<span style="color: #ff0000;">''</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>接下来，将这个函数加入到 PROMPT_COMMAND 中，保证 Bash 在创建 prompt 之前调用这个函数取得分支名称：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">PROMPT_COMMAND</span>=<span style="color: #ff0000;">&quot;find_git_branch; <span style="color: #007800;">$PROMPT_COMMAND</span>&quot;</span></pre></div></div>

<p>最后只要重新定义 PS1 变量即可：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Here is bash color codes you can use</span>
  <span style="color: #007800;">black</span>=$<span style="color: #ff0000;">'\[\e[1;30m\]'</span>
    <span style="color: #007800;">red</span>=$<span style="color: #ff0000;">'\[\e[1;31m\]'</span>
  <span style="color: #007800;">green</span>=$<span style="color: #ff0000;">'\[\e[1;32m\]'</span>
 <span style="color: #007800;">yellow</span>=$<span style="color: #ff0000;">'\[\e[1;33m\]'</span>
   <span style="color: #007800;">blue</span>=$<span style="color: #ff0000;">'\[\e[1;34m\]'</span>
<span style="color: #007800;">magenta</span>=$<span style="color: #ff0000;">'\[\e[1;35m\]'</span>
   <span style="color: #007800;">cyan</span>=$<span style="color: #ff0000;">'\[\e[1;36m\]'</span>
  <span style="color: #007800;">white</span>=$<span style="color: #ff0000;">'\[\e[1;37m\]'</span>
 <span style="color: #007800;">normal</span>=$<span style="color: #ff0000;">'\[\e[m\]'</span>
&nbsp;
<span style="color: #007800;">PS1</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$white</span>[<span style="color: #007800;">$magenta</span>\u<span style="color: #007800;">$white</span>@<span style="color: #007800;">$green</span>\h<span style="color: #007800;">$white</span>:<span style="color: #007800;">$cyan</span>\w<span style="color: #007800;">$yellow</span><span style="color: #000099; font-weight: bold;">\$</span>git_branch<span style="color: #007800;">$white</span>]<span style="color: #000099; font-weight: bold;">\$</span> <span style="color: #007800;">$normal</span>&quot;</span></pre></div></div>

<p>以上的代码你可以放在 ~/.profile 或者 ~/.bash_profile 等文件中即可，我的系统是 Snow Leopard，PS1 定义在 /etc/bashrc 中，所以我直接修改的这个文件。</p>
<p>最终效果如下：</p>
<div class="center"><a href="http://www.phpvim.net/wp-content/uploads/2010/06/git-branch-in-bash-prompt.png" onclick="return hs.expand(this);" class="highslide-image"><img src="http://www.phpvim.net/wp-content/uploads/2010/06/git-branch-in-bash-prompt-300x171.png" alt="image" title="Click to enlarge" /></a></div>
<p><br/></p>
<p><strong style="skyblue">UPDATE &#8211; 2010/06/23:</strong><br />
如果你安装了随 Git 附送的 <em>git-completion.sh</em> 子命令自动完成脚本，也可以使用该脚本提供的方法：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PS1</span>=<span style="color: #ff0000;">&quot;[\u@\h \W&quot;</span><span style="color: #ff0000;">'$(__git_ps1 &quot; (%s)&quot;)'</span><span style="color: #ff0000;">&quot;]<span style="color: #000099; font-weight: bold;">\$</span> &quot;</span></pre></div></div>

<p>Ubuntu 系统，请参考： /etc/bash_completion.d/git</p>
<p>参考文献：<br />
<cite><a href="">http://www.jonmaddox.com/2008/03/13/show-your-git-branch-name-in-your-prompt/</a><br />
<a href="">http://aaroncrane.co.uk/2009/03/git_branch_prompt/</a></cite></p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpvim.net/os/mac/git-branch-in-bash-prompt.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP CGI 中 fix_pathinfo 引起的安全隐患</title>
		<link>http://www.phpvim.net/web/php/security-risks-caused-by-fix-pathinfo.html</link>
		<comments>http://www.phpvim.net/web/php/security-risks-caused-by-fix-pathinfo.html#comments</comments>
		<pubDate>Sat, 22 May 2010 14:14:56 +0000</pubDate>
		<dc:creator>Verdana Mu</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[FastCGI]]></category>
		<category><![CDATA[Nginx]]></category>

		<guid isPermaLink="false">http://www.phpvim.net/?p=539</guid>
		<description><![CDATA[这两天网上开始疯传一个“nginx文件类型错误解析漏洞”，这个“漏洞”是这样的： 假设有如下的 URL：http://phpvim.net/foo.jpg，当访问 http://phpvim.net/foo.jpg/a.php 时，foo.jpg 将会被执行，如果 foo.jpg 是一个普通文件，那么 foo.jpg 的内容会被直接显示出来，但是如果把一段 php 代码保存为 foo.jpg，那么问题就来了，这段代码就会被直接执行。这对一个 Web 应用来说，所造成的后果无疑是毁灭性的。 关于这个问题，已有高手 laruence 做过详细的分析，这里再多啰嗦几句。 首先不管你是否有用到正则来解析 PATH_INFO，这个漏洞都是存在的。比如下面这个最基本的 nginx 配置： 1 2 3 4 5 6 location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } 漏洞同样会出现，如 laruence 所说，实际上这个漏洞和 nginx 真的没什么关系，nginx 只是个 Proxy，它只负责根据用户的配置文件，通过 fastcgi_param 指令将参数忠实地传递给 FastCGI Server，问题在于 FastCGI Server [...]]]></description>
			<content:encoded><![CDATA[<p>这两天网上开始疯传一个<a href="http://www.80sec.com/nginx-securit.html#more-163" targe="_blank">“nginx文件类型错误解析漏洞”</a>，这个“漏洞”是这样的：</p>
<p>假设有如下的 URL：http://phpvim.net/foo.jpg，当访问 http://phpvim.net/foo.jpg/a.php 时，foo.jpg 将会被执行，如果 foo.jpg 是一个普通文件，那么 foo.jpg 的内容会被直接显示出来，但是如果把一段 php 代码保存为 foo.jpg，那么问题就来了，这段代码就会被直接执行。这对一个 Web 应用来说，所造成的后果无疑是毁灭性的。</p>
<p>关于这个问题，已有高手 laruence 做过<a href="http://www.laruence.com/2010/05/20/1495.html" target="_blank">详细的分析</a>，这里再多啰嗦几句。</p>
<p>首先不管你是否有用到正则来解析 PATH_INFO，这个漏洞都是存在的。比如下面这个最基本的 nginx 配置：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="nginx" style="font-family:monospace;">location ~ \.php$ {
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    include       fastcgi_params;
    fastcgi_param SCRIPT_FILENAME   $document_root$fastcgi_script_name;
}</pre></td></tr></table></div>

<p>漏洞同样会出现，如 laruence 所说，实际上这个漏洞和 nginx 真的没什么关系，nginx 只是个 Proxy，它只负责根据用户的配置文件，通过 fastcgi_param 指令将参数忠实地传递给 FastCGI Server，问题在于 FastCGI Server 如何处理 nginx 提供的参数？</p>
<p>比如访问下面这个 URL：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="text" style="font-family:monospace;">http://phpvim.net/foo.jpg/a.php/b.php/c.php</pre></td></tr></table></div>

<p>那么根据上面给出的配置，nginx 传递给 FastCGI 的 SCRIPT_FILENAME 的值为：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="text" style="font-family:monospace;">/home/verdana/public_html/unsafe/foo.jpg/a.php/b.php/c.php</pre></td></tr></table></div>

<p>也就是 $_SERVER['ORIG_SCRIPT_FILENAME']。</p>
<p>当 php.ini 中 cgi.fix_pathinfo = 1 时，PHP CGI 以 / 为分隔符号从后向前依次检查如下路径：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="text" style="font-family:monospace;">/home/verdana/public_html/unsafe/foo.jpg/a.php/b.php/c.php
/home/verdana/public_html/unsafe/foo.jpg/a.php/b.php
/home/verdana/public_html/unsafe/foo.jpg/a.php
/home/verdana/public_html/unsafe/foo.jpg</pre></td></tr></table></div>

<p>直到找个某个存在的文件，如果这个文件是个非法的文件，so&#8230; 悲剧了~</p>
<p>PHP 会把这个文件当成 cgi 脚本执行，并赋值路径给 CGI 环境变量——SCRIPT_FILENAME，也就是 $_SERVER['SCRIPT_FILENAME'] 的值了。</p>
<p>在很多使用 php-fpm （<0.6） 的主机中也会出现这个问题，但新的 php-fpm 的已经关闭了 cgi.fix_pathinfo，如果你查看 phpinfo() 页面会发现这个选项已经不存在了，代码 ini_get(&#8220;cgi.fix_pathinfo&#8221;) 的返回值也是 &#8220;false&#8221;。</p>
<p>原因是似乎因为 APC 的一个 bug，当 cgi.fix_pathinfo 开启时，PATH_TRANSLATED 有可能是 NULL，从而引起内存异常，造成 php-fpm crash，所以 php-fpm 关闭这个选项。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpvim.net/web/php/security-risks-caused-by-fix-pathinfo.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>启动 PHP 内置 FastCGI Server 的脚本</title>
		<link>http://www.phpvim.net/web/php/script-for-php-buildin-fcgi-server.html</link>
		<comments>http://www.phpvim.net/web/php/script-for-php-buildin-fcgi-server.html#comments</comments>
		<pubDate>Fri, 30 Apr 2010 07:10:00 +0000</pubDate>
		<dc:creator>Verdana Mu</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.phpvim.net/?p=537</guid>
		<description><![CDATA[前几天把工作平台从 Ubuntu 9.10 Karmic 更新到了 10.04 Lucid，由于 Lucid 官方源自带了 PHP5.3.2，以前使用的 dotdeb 的源就没法用了，一直很喜欢这个源的，不但提供了 PHP5.3 而且还有 php5-fpm 这个很实用的 fcgi 进程管理器，这个在官方源里面是没有的。强行上了 dotdeb 虽然也可以，不过必然有很多包会出现依赖问题，处理这些依赖关系是件很烦心的事情。哥啥都不怕，就怕麻烦～ 对于 PHP 来说，php-fpm 还是最合适的，spawn-fcgi 这类东西就不用考虑了，我宁愿用 PHP5 内置的 FastCGI Server。 通过下面的命令启动服务器，监听 9000 端口： php-cgi -q -b 127.0.0.1:9000 &#38; 好了，配合 nginx，可以继续开始工作了，但是你会发现每隔一段时间就会出现 502 Bad Gateway 错误，因为 php-cgi 进程处理的请求数达到最大（默认500）自动退出了。 你需要设置两个环境变量： PHP_FCGI_CHILDREN &#8211; 派生子进程的数量 PHP_FCGI_MAX_REQUESTS &#8211; 每个子进程所能处理的最大请求数 配合这两个环境变量，启动内置的 FastCGI Server，保证 [...]]]></description>
			<content:encoded><![CDATA[<p>前几天把工作平台从 Ubuntu 9.10 Karmic 更新到了 10.04 Lucid，由于 Lucid 官方源自带了 PHP5.3.2，以前使用的 <a href="http://www.dotdeb.org">dotdeb</a> 的源就没法用了，一直很喜欢这个源的，不但提供了 PHP5.3 而且还有 php5-fpm 这个很实用的 fcgi 进程管理器，这个在官方源里面是没有的。强行上了 dotdeb 虽然也可以，不过必然有很多包会出现依赖问题，处理这些依赖关系是件很烦心的事情。哥啥都不怕，就怕麻烦～ <img src='http://www.phpvim.net/wp-includes/images/smilies/icon_exclaim.gif' alt=':!:' class='wp-smiley' />  </p>
<p>对于 PHP 来说，<a href="http://php-fpm.org">php-fpm</a> 还是最合适的，<a href="http://www.lighttpd.net">spawn-fcgi</a> 这类东西就不用考虑了，我宁愿用 PHP5 内置的 FastCGI Server。<br />
<span id="more-537"></span><br />
通过下面的命令启动服务器，监听 9000 端口：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">php-cgi <span style="color: #660033;">-q</span> <span style="color: #660033;">-b</span> 127.0.0.1:<span style="color: #000000;">9000</span> <span style="color: #000000; font-weight: bold;">&amp;</span></pre></div></div>

<p>好了，配合 nginx，可以继续开始工作了，但是你会发现每隔一段时间就会出现 502 Bad Gateway 错误，因为 php-cgi 进程处理的请求数达到最大（默认500）自动退出了。</p>
<p>你需要设置两个环境变量：<br />
PHP_FCGI_CHILDREN &#8211; 派生子进程的数量<br />
PHP_FCGI_MAX_REQUESTS &#8211; 每个子进程所能处理的最大请求数</p>
<p>配合这两个环境变量，启动内置的 FastCGI Server，保证 PHP 能够派生出子进程来负责处理请求，而不是由主进程来做。否则就会出现上面说的情况，达到 500 以后，自动退出。</p>
<p>下面是一个简单的脚本：</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
47
48
49
50
51
52
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash </span>
&nbsp;
<span style="color: #666666; font-style: italic;">## 参考：</span>
<span style="color: #666666; font-style: italic;">##</span>
<span style="color: #666666; font-style: italic;">##   http://php.net/manual/en/install.unix.lighttpd-14.php</span>
<span style="color: #666666; font-style: italic;">##   http://kovyrin.net/2006/05/30/nginx-php-fastcgi-howto</span>
<span style="color: #666666; font-style: italic;">##</span>
&nbsp;
<span style="color: #666666; font-style: italic;">## php-cgi 的文件路径</span>
<span style="color: #007800;">PHPFCGI</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">which</span> php-cgi<span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #666666; font-style: italic;">## PID 文件路径</span>
<span style="color: #007800;">PHP_PID</span>=<span style="color: #ff0000;">&quot;/tmp/php.pid&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">## 绑定 TCP 地址</span>
<span style="color: #007800;">FCGI_BIND_ADDRESS</span>=<span style="color: #ff0000;">&quot;127.0.0.1:9000&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">## 绑定到 Unix domain socket</span>
<span style="color: #666666; font-style: italic;">#FCGI_BIND_ADDRESS=&quot;/tmp/php.sock&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">## 派生出多少个 PHP 子进程</span>
<span style="color: #666666; font-style: italic;">## 其中不包括主进程</span>
<span style="color: #007800;">PHP_FCGI_CHILDREN</span>=<span style="color: #000000;">16</span>
&nbsp;
<span style="color: #666666; font-style: italic;">## 每个 PHP 进程处理的最大请求数</span>
<span style="color: #007800;">PHP_FCGI_MAX_REQUESTS</span>=<span style="color: #000000;">4096</span>
&nbsp;
<span style="color: #666666; font-style: italic;">## 用户</span>
<span style="color: #007800;">USERID</span>=verdana
&nbsp;
<span style="color: #666666; font-style: italic;">################## no config below this line</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># 根据用户不同，切换启动命令</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">test</span> x<span style="color: #007800;">$UID</span> = x0; <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #007800;">CMD</span>=<span style="color: #ff0000;">&quot;/bin/su -m -c <span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #007800;">$PHPFCGI</span> -q -b <span style="color: #007800;">$FCGI_BIND_ADDRESS</span><span style="color: #000099; font-weight: bold;">\&quot;</span> <span style="color: #007800;">$USERID</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">else</span>
  <span style="color: #007800;">CMD</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$PHPFCGI</span> -b <span style="color: #007800;">$FCGI_BIND_ADDRESS</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$CMD</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># 相关的环境变量</span>
<span style="color: #007800;">E</span>=<span style="color: #ff0000;">&quot;PHP_FCGI_CHILDREN=<span style="color: #007800;">$PHP_FCGI_CHILDREN</span> PHP_FCGI_MAX_REQUESTS=<span style="color: #007800;">$PHP_FCGI_MAX_REQUESTS</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># 忽略其他的环境变量，以一个干净的环境启动</span>
<span style="color: #c20cb9; font-weight: bold;">nohup</span> <span style="color: #c20cb9; font-weight: bold;">env</span> - <span style="color: #007800;">$E</span> <span style="color: #c20cb9; font-weight: bold;">sh</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$CMD</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000; font-weight: bold;">&amp;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># 记录 PHP 主进程的 PID</span>
<span style="color: #666666; font-style: italic;"># $! 返回的是 sh 的 PID</span>
<span style="color: #666666; font-style: italic;"># 找到所有 php-cgi 进程中最小的 PID，就是主进程的 PID</span>
<span style="color: #007800;">MASTER_PID</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ps</span> <span style="color: #660033;">-e</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'php-cgi'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">'1p'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$MASTER_PID</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PHP_PID</span>&quot;</span></pre></td></tr></table></div>

<p>如何关闭呢？<br />
可以一次性杀灭所有的 php-cgi 进程：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ps</span> <span style="color: #660033;">-e</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> php-cgi <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #c20cb9; font-weight: bold;">kill</span></pre></div></div>

<p>只弄死主进程也可以达到相同的效果，所有子进程也会随之消失：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>php.pid <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #c20cb9; font-weight: bold;">kill</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.phpvim.net/web/php/script-for-php-buildin-fcgi-server.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>一切都已改变</title>
		<link>http://www.phpvim.net/journal/everything-is-changing.html</link>
		<comments>http://www.phpvim.net/journal/everything-is-changing.html#comments</comments>
		<pubDate>Wed, 28 Apr 2010 19:05:32 +0000</pubDate>
		<dc:creator>Verdana Mu</dc:creator>
				<category><![CDATA[Journal]]></category>

		<guid isPermaLink="false">http://www.phpvim.net/?p=535</guid>
		<description><![CDATA[搬到孵化园已经一个月了，很忙，很烦&#8230; 从去年的年底到现在，对我来说有了很大的变化，也有不少的收获。在朋友的帮助下，顺利地组建了自己的 Web 外包团队，落户在了高新孵化园。网站外包，真的是件很没技术含量的事情，也没什么油水可捞，不过倒是一条锻炼团队的途径。 自己也和哥们从东门建设路住了近10年的老房子里面搬到了外双楠，传说中非富即贵的富人区，有多少富贵人家我不知道，我只知道外面吃得东西真他娘的贵！一个人随便找个馆子一顿吃下来就几十块就没了，这也算是刺激自己努力赚钱的动力吧~想想你如果吃了N年的炒饭，面条，而现在还在吃这些的东西，那就太凄凉了！ 原来住的老房子在建设路，某半死不活的国企职工宿舍，风水很不好，帮我们看房子的风水师傅说，这里叫做空亡之地。我对命理学一窍不通，不过从字面上看也知道不是什么好地方。大师还帮我们看了八字，给我解释的东西，我都忘光了，只记得关于华盖的一些话。命里有华盖的人通常都是才华横溢、性情恬淡的主，被人说自己聪明当然是件开心的事情，不过后来我发现了其实大师也有很多话没有说，那就是华盖通常也意味着不愿与人交往，常常感到孤独，而且通常与宗教有缘，好吧，我命里不但有华盖，而且还是三个，只能叹一声：马勒戈壁的！ 本来还想问问姻缘的，没好意思！ 搬家的时候，带了以前女友的照片，放在电脑桌上，为此还被哥么给嘲笑了一番。笑就笑吧，我忘不了这个女人，和她之间发生的一切，已成昨日黄花。快3年过去了，唯一留下的，就是这张照片还有那永远挥之不去的浓浓情意萦绕在心头。我一直在想，什么时候可以再见到她呢？只是见见也好，怕只怕这辈子再也看不到她了。我为爱烦恼，只因太执着，人常说，男子汉大丈夫，当拿得起放得下，我拿起了这份感情，却再难放下。 父亲常常打电话催我结婚，这样的日子持续了1年多了直到现在依然如此，有段时间几乎是以每天1，2个电话的高频率给我洗脑，灌输男大当婚、女大当嫁的观念，搞的我一听到手机响，就郁闷不堪，很想把手机从窗户扔出去。不过电话还是要接的，于是每次只能信誓旦旦的和父亲保证一定给他找个好儿媳，就这样日子一天天的过去，儿媳还是没着落，父亲也渐渐不再像以前那样紧紧逼迫，只是偶尔还是会提起，而我也懒的再提那些陈词滥调的保证了。呵呵，像我这样的没钱没车没房的头顶三华盖的孤僻三无宅男，想要找个老婆，还真是件极具挑战性的事。在天朝这个环境里，根本是不可能的嘛，哪怕天上真的会掉下个林妹妹，只怕也是脸先着地的，好吧，我宁愿孤独终老，也不愿意委屈自己，寂寞归寂寞，不过反过来想，不也是一生自由自在，不受约束，逍遥快活的么？哎，就当我阿Q好了！笑~]]></description>
			<content:encoded><![CDATA[<p>搬到孵化园已经一个月了，很忙，很烦&#8230;</p>
<p>从去年的年底到现在，对我来说有了很大的变化，也有不少的收获。在朋友的帮助下，顺利地组建了自己的 Web 外包团队，落户在了高新孵化园。网站外包，真的是件很没技术含量的事情，也没什么油水可捞，不过倒是一条锻炼团队的途径。</p>
<p>自己也和哥们从东门建设路住了近10年的老房子里面搬到了外双楠，传说中非富即贵的富人区，有多少富贵人家我不知道，我只知道外面吃得东西真他娘的贵！一个人随便找个馆子一顿吃下来就几十块就没了，这也算是刺激自己努力赚钱的动力吧~想想你如果吃了N年的炒饭，面条，而现在还在吃这些的东西，那就太凄凉了！</p>
<p>原来住的老房子在建设路，某半死不活的国企职工宿舍，风水很不好，帮我们看房子的风水师傅说，这里叫做空亡之地。我对命理学一窍不通，不过从字面上看也知道不是什么好地方。大师还帮我们看了八字，给我解释的东西，我都忘光了，只记得关于华盖的一些话。命里有华盖的人通常都是才华横溢、性情恬淡的主，被人说自己聪明当然是件开心的事情，不过后来我发现了其实大师也有很多话没有说，那就是华盖通常也意味着不愿与人交往，常常感到孤独，而且通常与宗教有缘，好吧，我命里不但有华盖，而且还是三个，只能叹一声：马勒戈壁的！</p>
<p>本来还想问问姻缘的，没好意思！ <img src='http://www.phpvim.net/wp-includes/images/smilies/icon_redface.gif' alt=':oops:' class='wp-smiley' />  </p>
<p>搬家的时候，带了以前女友的照片，放在电脑桌上，为此还被哥么给嘲笑了一番。笑就笑吧，我忘不了这个女人，和她之间发生的一切，已成昨日黄花。快3年过去了，唯一留下的，就是这张照片还有那永远挥之不去的浓浓情意萦绕在心头。我一直在想，什么时候可以再见到她呢？只是见见也好，怕只怕这辈子再也看不到她了。我为爱烦恼，只因太执着，人常说，男子汉大丈夫，当拿得起放得下，我拿起了这份感情，却再难放下。</p>
<p>父亲常常打电话催我结婚，这样的日子持续了1年多了直到现在依然如此，有段时间几乎是以每天1，2个电话的高频率给我洗脑，灌输男大当婚、女大当嫁的观念，搞的我一听到手机响，就郁闷不堪，很想把手机从窗户扔出去。不过电话还是要接的，于是每次只能信誓旦旦的和父亲保证一定给他找个好儿媳，就这样日子一天天的过去，儿媳还是没着落，父亲也渐渐不再像以前那样紧紧逼迫，只是偶尔还是会提起，而我也懒的再提那些陈词滥调的保证了。呵呵，像我这样的没钱没车没房的头顶三华盖的孤僻三无宅男，想要找个老婆，还真是件极具挑战性的事。在天朝这个环境里，根本是不可能的嘛，哪怕天上真的会掉下个林妹妹，只怕也是脸先着地的，好吧，我宁愿孤独终老，也不愿意委屈自己，寂寞归寂寞，不过反过来想，不也是一生自由自在，不受约束，逍遥快活的么？哎，就当我阿Q好了！笑~  <img src='http://www.phpvim.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':grin:' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpvim.net/journal/everything-is-changing.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

