<?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>exp2Up</title>
	<atom:link href="http://www.i2up.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.i2up.com</link>
	<description>努力赚钱，享受生活。</description>
	<lastBuildDate>Wed, 14 Sep 2011 03:36:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>php多进程时，遇到mysql has gone away的解决</title>
		<link>http://www.i2up.com/2011/09/14/php%e5%a4%9a%e8%bf%9b%e7%a8%8b%e6%97%b6%ef%bc%8c%e9%81%87%e5%88%b0mysql-has-gone-away%e7%9a%84%e8%a7%a3%e5%86%b3/</link>
		<comments>http://www.i2up.com/2011/09/14/php%e5%a4%9a%e8%bf%9b%e7%a8%8b%e6%97%b6%ef%bc%8c%e9%81%87%e5%88%b0mysql-has-gone-away%e7%9a%84%e8%a7%a3%e5%86%b3/#comments</comments>
		<pubDate>Wed, 14 Sep 2011 03:36:32 +0000</pubDate>
		<dc:creator>YuYii</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.i2up.com/?p=612</guid>
		<description><![CDATA[首先，描述下大致情况，后台脚本方式运行PHP，因为有多个任务需要同时运行，采用了PHP的多进程方式。 但是发现程序很容易就遇到mysql has gone away的问题。 每个子进程新建自己的数据库连接，长连接时需要用mysql_ping保持 相关文章: bind_textdomain_codeset undefined PHP中控制proc_open的执行时间 使用apache 的PHP cgi时遇到的Internal Server Error可能原因 PHP json解析的注意事项 使用cgi作为php运行的命令需要注意的]]></description>
			<content:encoded><![CDATA[<p>首先，描述下大致情况，后台脚本方式运行PHP，因为有多个任务需要同时运行，采用了PHP的多进程方式。</p>
<p>但是发现程序很容易就遇到mysql has gone away的问题。</p>
<p>每个子进程新建自己的数据库连接，长连接时需要用mysql_ping保持</p>

<p><strong>相关文章:</strong></p>
<ul>
<li><a href="http://www.i2up.com/2011/06/06/bind_textdomain_codeset-undefined/">bind_textdomain_codeset undefined</a></li>
<li><a href="http://www.i2up.com/2011/04/21/php%e4%b8%ad%e6%8e%a7%e5%88%b6proc_open%e7%9a%84%e6%89%a7%e8%a1%8c%e6%97%b6%e9%97%b4/">PHP中控制proc_open的执行时间</a></li>
<li><a href="http://www.i2up.com/2011/03/08/%e4%bd%bf%e7%94%a8apache-%e7%9a%84php-cgi%e6%97%b6%e9%81%87%e5%88%b0%e7%9a%84internal-server-error%e5%8f%af%e8%83%bd%e5%8e%9f%e5%9b%a0/">使用apache 的PHP cgi时遇到的Internal Server Error可能原因</a></li>
<li><a href="http://www.i2up.com/2011/01/30/php-json%e8%a7%a3%e6%9e%90%e7%9a%84%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a1%b9/">PHP json解析的注意事项</a></li>
<li><a href="http://www.i2up.com/2011/01/10/%e4%bd%bf%e7%94%a8cgi%e4%bd%9c%e4%b8%baphp%e8%bf%90%e8%a1%8c%e7%9a%84%e5%91%bd%e4%bb%a4%e9%9c%80%e8%a6%81%e6%b3%a8%e6%84%8f%e7%9a%84/">使用cgi作为php运行的命令需要注意的</a></li>
</ul><br />
]]></content:encoded>
			<wfw:commentRss>http://www.i2up.com/2011/09/14/php%e5%a4%9a%e8%bf%9b%e7%a8%8b%e6%97%b6%ef%bc%8c%e9%81%87%e5%88%b0mysql-has-gone-away%e7%9a%84%e8%a7%a3%e5%86%b3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>bind_textdomain_codeset undefined</title>
		<link>http://www.i2up.com/2011/06/06/bind_textdomain_codeset-undefined/</link>
		<comments>http://www.i2up.com/2011/06/06/bind_textdomain_codeset-undefined/#comments</comments>
		<pubDate>Mon, 06 Jun 2011 04:41:18 +0000</pubDate>
		<dc:creator>YuYii</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[gettext]]></category>

		<guid isPermaLink="false">http://www.exp2up.com/?p=608</guid>
		<description><![CDATA[雪豹上，对php动态编译gettext成功后，发现这个函数还是不能用。 编译的一般过程是： 1。 编译gettext 2。 到php的扩展目录gettext下 phpize然后编译 编译安装后，发现部分函数可用，部分不可用。 排查了很久，通过在ext/gettext/ 目录下 configure编译时，输出 checking for GNU gettext support&#8230; yes, shared checking for bindtextdomain in -lintl&#8230; yes checking for ngettext in -lintl&#8230; no checking for dngettext in -lintl&#8230; no checking for dcngettext in -lintl&#8230; no checking for bind_textdomain_codeset in -lintl&#8230; no 很明显，我要的函数，没给编进去 进行跟踪，发现是这几句的测试代码，都没加-L库，很奇怪。因为我的路径比较特殊，指定在了/src/gettext下。继续跟踪，在configure脚本中发现一句 (4200) LDFLAGS=$O_LDFLAGS 好像是把LDFLAGS还原回去，不知道configure脚本为啥这么做。直接给注释了，再重新编，就都是yes了。 另，php版本是5.3.4 相关文章: [...]]]></description>
			<content:encoded><![CDATA[<p>雪豹上，对php动态编译gettext成功后，发现这个函数还是不能用。</p>
<p>编译的一般过程是：<br />
1。 编译gettext<br />
2。 到php的扩展目录gettext下 phpize然后编译</p>
<p>编译安装后，发现部分函数可用，部分不可用。</p>
<p>排查了很久，通过在ext/gettext/ 目录下 configure编译时，输出</p>
<p>checking for GNU gettext support&#8230; yes, shared<br />
checking for bindtextdomain in -lintl&#8230; yes<br />
checking for ngettext in -lintl&#8230; no<br />
checking for dngettext in -lintl&#8230; no<br />
checking for dcngettext in -lintl&#8230; no<br />
checking for bind_textdomain_codeset in -lintl&#8230; no</p>
<p>很明显，我要的函数，没给编进去<br />
进行跟踪，发现是这几句的测试代码，都没加-L库，很奇怪。因为我的路径比较特殊，指定在了/src/gettext下。继续跟踪，在configure脚本中发现一句 (4200)</p>
<p>LDFLAGS=$O_LDFLAGS</p>
<p>好像是把LDFLAGS还原回去，不知道configure脚本为啥这么做。直接给注释了，再重新编，就都是yes了。</p>
<p>另，php版本是5.3.4</p>

<p><strong>相关文章:</strong></p>
<ul>
<li><a href="http://www.i2up.com/2011/09/14/php%e5%a4%9a%e8%bf%9b%e7%a8%8b%e6%97%b6%ef%bc%8c%e9%81%87%e5%88%b0mysql-has-gone-away%e7%9a%84%e8%a7%a3%e5%86%b3/">php多进程时，遇到mysql has gone away的解决</a></li>
<li><a href="http://www.i2up.com/2011/04/21/php%e4%b8%ad%e6%8e%a7%e5%88%b6proc_open%e7%9a%84%e6%89%a7%e8%a1%8c%e6%97%b6%e9%97%b4/">PHP中控制proc_open的执行时间</a></li>
<li><a href="http://www.i2up.com/2011/03/08/%e4%bd%bf%e7%94%a8apache-%e7%9a%84php-cgi%e6%97%b6%e9%81%87%e5%88%b0%e7%9a%84internal-server-error%e5%8f%af%e8%83%bd%e5%8e%9f%e5%9b%a0/">使用apache 的PHP cgi时遇到的Internal Server Error可能原因</a></li>
<li><a href="http://www.i2up.com/2011/01/30/php-json%e8%a7%a3%e6%9e%90%e7%9a%84%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a1%b9/">PHP json解析的注意事项</a></li>
<li><a href="http://www.i2up.com/2011/01/10/%e4%bd%bf%e7%94%a8cgi%e4%bd%9c%e4%b8%baphp%e8%bf%90%e8%a1%8c%e7%9a%84%e5%91%bd%e4%bb%a4%e9%9c%80%e8%a6%81%e6%b3%a8%e6%84%8f%e7%9a%84/">使用cgi作为php运行的命令需要注意的</a></li>
</ul><br />
]]></content:encoded>
			<wfw:commentRss>http://www.i2up.com/2011/06/06/bind_textdomain_codeset-undefined/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>EICAR标准病毒测试文件</title>
		<link>http://www.i2up.com/2011/05/01/eicar%e6%a0%87%e5%87%86%e7%97%85%e6%af%92%e6%b5%8b%e8%af%95%e6%96%87%e4%bb%b6/</link>
		<comments>http://www.i2up.com/2011/05/01/eicar%e6%a0%87%e5%87%86%e7%97%85%e6%af%92%e6%b5%8b%e8%af%95%e6%96%87%e4%bb%b6/#comments</comments>
		<pubDate>Sun, 01 May 2011 05:53:52 +0000</pubDate>
		<dc:creator>YuYii</dc:creator>
				<category><![CDATA[随便写写]]></category>
		<category><![CDATA[病毒]]></category>

		<guid isPermaLink="false">http://www.exp2up.com/?p=602</guid>
		<description><![CDATA[﻿将一下内容保存为文件即可 X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H* 相关文章: 悲剧了，钱包丢了 郁闷,买了个很弱的VPS 2010年的birthday present 新年第2天败了台WII 女人开车]]></description>
			<content:encoded><![CDATA[<p>﻿将一下内容保存为文件即可</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*</li></ol></div>

<p><strong>相关文章:</strong></p>
<ul>
<li><a href="http://www.i2up.com/2010/06/14/%e6%82%b2%e5%89%a7%e4%ba%86%ef%bc%8c%e9%92%b1%e5%8c%85%e4%b8%a2%e4%ba%86/">悲剧了，钱包丢了</a></li>
<li><a href="http://www.i2up.com/2010/05/14/%e9%83%81%e9%97%b7%e4%b9%b0%e4%ba%86%e4%b8%aa%e5%be%88%e5%bc%b1%e7%9a%84vps/">郁闷,买了个很弱的VPS</a></li>
<li><a href="http://www.i2up.com/2010/04/01/2010%e5%b9%b4%e7%9a%84birthday-present/">2010年的birthday present</a></li>
<li><a href="http://www.i2up.com/2010/01/02/%e6%96%b0%e5%b9%b4%e7%ac%ac2%e5%a4%a9%e8%b4%a5%e4%ba%86%e5%8f%b0wii/">新年第2天败了台WII</a></li>
<li><a href="http://www.i2up.com/2009/01/24/%e5%a5%b3%e4%ba%ba%e5%bc%80%e8%bd%a6/">女人开车</a></li>
</ul><br />
]]></content:encoded>
			<wfw:commentRss>http://www.i2up.com/2011/05/01/eicar%e6%a0%87%e5%87%86%e7%97%85%e6%af%92%e6%b5%8b%e8%af%95%e6%96%87%e4%bb%b6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mysql编码</title>
		<link>http://www.i2up.com/2011/04/25/mysql%e7%bc%96%e7%a0%81/</link>
		<comments>http://www.i2up.com/2011/04/25/mysql%e7%bc%96%e7%a0%81/#comments</comments>
		<pubDate>Sun, 24 Apr 2011 17:07:29 +0000</pubDate>
		<dc:creator>YuYii</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.exp2up.com/?p=599</guid>
		<description><![CDATA[set names gbk 等同于以下3句 set character_set_client=gbk; 这句告诉 MySQL 我接下来要用的 SQL 语句的编码是 GBK 的 set character_set_connection=gbk; 这句 告诉 MySQL 要把 SQL 语句转换成 GBK 进行处理 set character_set_results=gbk; 这句告诉 MYSQL 查询返回的结果要统一都转换成 GBK 编码的 另外可以使用status命令或者show variables like &#8216;char%&#8217; 查看当前数据库的默认编码状况 +&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+ &#124; Variable_name            &#124; Value                     [...]]]></description>
			<content:encoded><![CDATA[<p>set names gbk 等同于以下3句<br />
set character_set_client=gbk; 这句告诉 MySQL 我接下来要用的 SQL 语句的编码是 GBK 的<br />
set character_set_connection=gbk; 这句 告诉 MySQL 要把 SQL 语句转换成 GBK 进行处理<br />
set character_set_results=gbk; 这句告诉 MYSQL 查询返回的结果要统一都转换成 GBK 编码的</p>
<p>另外可以使用status命令或者show variables like &#8216;char%&#8217; 查看当前数据库的默认编码状况</p>
<div id="_mcePaste">+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+</div>
<div id="_mcePaste">| Variable_name            | Value                                   |</div>
<div id="_mcePaste">+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+</div>
<div id="_mcePaste">| character_set_client     | latin1                                  |</div>
<div id="_mcePaste">| character_set_connection | latin1                                  |</div>
<div id="_mcePaste">| character_set_database   | utf8                                    |</div>
<div id="_mcePaste">| character_set_filesystem | binary                                  |</div>
<div id="_mcePaste">| character_set_results    | latin1                                  |</div>
<div id="_mcePaste">| character_set_server     | latin1                                  |</div>
<div id="_mcePaste">| character_set_system     | utf8                                    |</div>
<div id="_mcePaste">| character_sets_dir       | /opt/local/share/mysql5/mysql/charsets/ |</div>
<div id="_mcePaste">+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+</div>

<p><strong>相关文章:</strong></p>
<ul>
<li><a href="http://www.i2up.com/2011/01/10/phpmyadmin%e9%87%8c%e6%89%be%e4%b8%8d%e5%88%b0gbk%e7%bc%96%e7%a0%81/">phpmyadmin里找不到gbk编码</a></li>
<li><a href="http://www.i2up.com/2010/06/10/%e8%bf%9c%e7%a8%8b%e8%bf%9e%e6%8e%a5mysql%e9%80%9f%e5%ba%a6%e6%85%a2%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/">远程连接mysql速度慢的解决办法</a></li>
<li><a href="http://www.i2up.com/2010/03/01/mysql%e7%89%a9%e7%90%86%e5%a4%87%e4%bb%bd%e6%81%a2%e5%a4%8d%e8%a1%a8%e4%b8%a2%e5%a4%b1/">mysql物理备份恢复表丢失</a></li>
<li><a href="http://www.i2up.com/2009/05/27/%e5%85%b3%e4%ba%8eleopard%e4%b8%8asafari%e7%9a%84%e7%bc%93%e5%ad%98/">关于leopard上safari的缓存</a></li>
<li><a href="http://www.i2up.com/2009/04/17/phpmyadmin%e5%87%ba%e7%8e%b0access-deny%e7%9a%84%e9%94%99%e8%af%af/">phpmyadmin出现access deny的错误</a></li>
</ul><br />
]]></content:encoded>
			<wfw:commentRss>http://www.i2up.com/2011/04/25/mysql%e7%bc%96%e7%a0%81/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>自建CA和服务器证书</title>
		<link>http://www.i2up.com/2011/04/21/%e8%87%aa%e5%bb%baca%e5%92%8c%e6%9c%8d%e5%8a%a1%e5%99%a8%e8%af%81%e4%b9%a6/</link>
		<comments>http://www.i2up.com/2011/04/21/%e8%87%aa%e5%bb%baca%e5%92%8c%e6%9c%8d%e5%8a%a1%e5%99%a8%e8%af%81%e4%b9%a6/#comments</comments>
		<pubDate>Thu, 21 Apr 2011 08:29:38 +0000</pubDate>
		<dc:creator>YuYii</dc:creator>
				<category><![CDATA[PKI]]></category>
		<category><![CDATA[openssl]]></category>

		<guid isPermaLink="false">http://www.exp2up.com/?p=597</guid>
		<description><![CDATA[openssl genrsa -des3 -out ca.key 1024 //创建CA的私钥 openssl req -new -x509 -days 365 -key ca.key -out ca.crt //根据私钥创建自签名的CA证书 openssl genrsa -des3 -out server.key 1024 //创建web服务器的私钥 openssl req -new -key server.key -out server.csr //根据私钥创建证书申请 openssl x509 -CA ca_crt -CAcreateserial -req -in server.csr -CAkey ca_key -out server.crt //签名server.csr 生成server.crt 相关文章: PHP的UTF16转UTF8代码 【存】PKI常见证书格式和转换]]></description>
			<content:encoded><![CDATA[<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">openssl genrsa -des3 -out ca.key 1024 //创建CA的私钥</li>
<li>openssl req -new -x509 -days 365 -key ca.key -out ca.crt //根据私钥创建自签名的CA证书</li>
<li>openssl genrsa -des3 -out server.key 1024 //创建web服务器的私钥</li>
<li>openssl req -new -key server.key -out server.csr //根据私钥创建证书申请</li>
<li>openssl x509 -CA ca_crt -CAcreateserial -req -in server.csr -CAkey ca_key -out server.crt //签名server.csr 生成server.crt</li></ol></div>

<p><strong>相关文章:</strong></p>
<ul>
<li><a href="http://www.i2up.com/2008/11/07/php%e7%9a%84utf16%e8%bd%acutf8%e4%bb%a3%e7%a0%81/">PHP的UTF16转UTF8代码</a></li>
<li><a href="http://www.i2up.com/2008/10/08/%e3%80%90%e5%ad%98%e3%80%91pki%e5%b8%b8%e8%a7%81%e8%af%81%e4%b9%a6%e6%a0%bc%e5%bc%8f%e5%92%8c%e8%bd%ac%e6%8d%a2/">【存】PKI常见证书格式和转换</a></li>
</ul><br />
]]></content:encoded>
			<wfw:commentRss>http://www.i2up.com/2011/04/21/%e8%87%aa%e5%bb%baca%e5%92%8c%e6%9c%8d%e5%8a%a1%e5%99%a8%e8%af%81%e4%b9%a6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP中控制proc_open的执行时间</title>
		<link>http://www.i2up.com/2011/04/21/php%e4%b8%ad%e6%8e%a7%e5%88%b6proc_open%e7%9a%84%e6%89%a7%e8%a1%8c%e6%97%b6%e9%97%b4/</link>
		<comments>http://www.i2up.com/2011/04/21/php%e4%b8%ad%e6%8e%a7%e5%88%b6proc_open%e7%9a%84%e6%89%a7%e8%a1%8c%e6%97%b6%e9%97%b4/#comments</comments>
		<pubDate>Thu, 21 Apr 2011 06:38:31 +0000</pubDate>
		<dc:creator>YuYii</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[fork]]></category>
		<category><![CDATA[并发]]></category>

		<guid isPermaLink="false">http://www.exp2up.com/?p=594</guid>
		<description><![CDATA[目前想到有两个办法。 一个是fork方式。 发现直接通过进程的alarm信号方式无法控制proc_open的执行。所以用fork方式，通过fork让子进程执行proc_open，父进程则通过alarm的方式控制时间。但是这么做会造成如果有输出值的话会很麻烦，要让子进程一直执行下去，因为没找到好的办法让父进程能获取子进程的输出。当然通过进程间通信能解决，但是太麻烦了。。。 另外个stream_select方式 //cmd为要执行的程序， timeout是超时时间 &#160; &#160; &#160;&#160; $descriptorspec = array( &#160; &#160; 0 =&#62; array(&#34;pipe&#34;, &#34;r&#34;), &#160; &#160; 1 =&#62; array(&#34;pipe&#34;, &#34;w&#34;), &#160; &#160; 2 =&#62; array(&#34;pipe&#34;, &#34;w&#34;) &#160; &#160; ); &#160; &#160; &#160; &#160; $process = proc_open($cmd, $descriptorspec, $pipes); &#160; &#160; $stdout_str = $stderr_str = &#34;&#34;; &#160; &#160; &#160; if&#160;(is_resource($process)) { &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>目前想到有两个办法。</p>
<p>一个是fork方式。<br />
发现直接通过进程的alarm信号方式无法控制proc_open的执行。所以用fork方式，通过fork让子进程执行proc_open，父进程则通过alarm的方式控制时间。但是这么做会造成如果有输出值的话会很麻烦，要让子进程一直执行下去，因为没找到好的办法让父进程能获取子进程的输出。当然通过进程间通信能解决，但是太麻烦了。。。</p>
<p>另外个stream_select方式<br />
<span id="more-594"></span></p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: #ffa500;">//cmd为要执行的程序， timeout是超时时间</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp;&nbsp; </span><span style="color: #00008b;">$descriptorspec</span><span style="color: Gray;"> = </span><span style="color: Green;">array</span><span style="color: Olive;">(</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; </span><span style="color: Maroon;">0</span><span style="color: Gray;"> =&gt; </span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">pipe</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">, </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">r</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;">,</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; </span><span style="color: Maroon;">1</span><span style="color: Gray;"> =&gt; </span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">pipe</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">, </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">w</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;">,</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; </span><span style="color: Maroon;">2</span><span style="color: Gray;"> =&gt; </span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">pipe</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">, </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">w</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; </span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$process</span><span style="color: Gray;"> = </span><span style="color: Blue;">proc_open</span><span style="color: Olive;">(</span><span style="color: #00008b;">$cmd</span><span style="color: Gray;">, </span><span style="color: #00008b;">$descriptorspec</span><span style="color: Gray;">, </span><span style="color: #00008b;">$pipes</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; </span><span style="color: #00008b;">$stdout_str</span><span style="color: Gray;"> = </span><span style="color: #00008b;">$stderr_str</span><span style="color: Gray;"> = </span><span style="color: #8b0000;">&quot;&quot;</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Blue;">is_resource</span><span style="color: Olive;">(</span><span style="color: #00008b;">$process</span><span style="color: Olive;">))</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #ffa500;">//执行成功</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">stream_set_blocking</span><span style="color: Olive;">(</span><span style="color: #00008b;">$pipes</span><span style="color: Olive;">[</span><span style="color: Maroon;">1</span><span style="color: Olive;">]</span><span style="color: Gray;">, </span><span style="color: Maroon;">0</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">stream_set_blocking</span><span style="color: Olive;">(</span><span style="color: #00008b;">$pipes</span><span style="color: Olive;">[</span><span style="color: Maroon;">2</span><span style="color: Olive;">]</span><span style="color: Gray;">, </span><span style="color: Maroon;">0</span><span style="color: Olive;">)</span><span style="color: Gray;">;&nbsp; </span><span style="color: #ffa500;">//不阻塞</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">fwrite</span><span style="color: Olive;">(</span><span style="color: #00008b;">$pipes</span><span style="color: Olive;">[</span><span style="color: Maroon;">0</span><span style="color: Olive;">]</span><span style="color: Gray;">, </span><span style="color: #00008b;">$stdin_str</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">fclose</span><span style="color: Olive;">(</span><span style="color: #00008b;">$pipes</span><span style="color: Olive;">[</span><span style="color: Maroon;">0</span><span style="color: Olive;">])</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #ffa500;">//设置超时时钟</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$endtime</span><span style="color: Gray;"> = </span><span style="color: Blue;">time</span><span style="color: Olive;">()</span><span style="color: Gray;"> + </span><span style="color: #00008b;">$timeout</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">do</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$timeleft</span><span style="color: Gray;"> = </span><span style="color: #00008b;">$endtime</span><span style="color: Gray;"> - </span><span style="color: Blue;">time</span><span style="color: Olive;">()</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$ret</span><span style="color: Gray;"> = </span><span style="color: Blue;">stream_select</span><span style="color: Olive;">(</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$read</span><span style="color: Gray;"> = </span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: #00008b;">$pipes</span><span style="color: Olive;">[</span><span style="color: Maroon;">1</span><span style="color: Olive;">]</span><span style="color: Gray;">,</span><span style="color: #00008b;">$pipes</span><span style="color: Olive;">[</span><span style="color: Maroon;">2</span><span style="color: Olive;">])</span><span style="color: Gray;">,</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$write</span><span style="color: Gray;"> = </span><span style="color: Green;">null</span><span style="color: Gray;">,</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$except</span><span style="color: Gray;"> = </span><span style="color: Green;">null</span><span style="color: Gray;">,</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$timeleft</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: #00008b;">$ret</span><span style="color: Gray;"> === </span><span style="color: Green;">false</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$err</span><span style="color: Gray;"> = </span><span style="color: Green;">true</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">break</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">else</span><span style="color: Gray;"> </span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: #00008b;">$ret</span><span style="color: Gray;"> === </span><span style="color: Maroon;">0</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$timeleft</span><span style="color: Gray;"> = </span><span style="color: Maroon;">0</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">break</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">else</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">foreach</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: #00008b;">$read</span><span style="color: Gray;"> </span><span style="color: Green;">as</span><span style="color: Gray;"> </span><span style="color: #00008b;">$sock</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: #00008b;">$sock</span><span style="color: Gray;"> === </span><span style="color: #00008b;">$pipes</span><span style="color: Olive;">[</span><span style="color: Maroon;">1</span><span style="color: Olive;">])</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$stdout_str</span><span style="color: Gray;"> .= </span><span style="color: Blue;">fread</span><span style="color: Olive;">(</span><span style="color: #00008b;">$sock</span><span style="color: Gray;">, </span><span style="color: Maroon;">4096</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">else</span><span style="color: Gray;"> </span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: #00008b;">$sock</span><span style="color: Gray;"> === </span><span style="color: #00008b;">$pipes</span><span style="color: Olive;">[</span><span style="color: Maroon;">2</span><span style="color: Olive;">])</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$stderr_str</span><span style="color: Gray;"> .= </span><span style="color: Blue;">fread</span><span style="color: Olive;">(</span><span style="color: #00008b;">$sock</span><span style="color: Gray;">, </span><span style="color: Maroon;">4096</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span><span style="color: Green;">while</span><span style="color: Olive;">((</span><span style="color: Blue;">feof</span><span style="color: Olive;">(</span><span style="color: #00008b;">$pipes</span><span style="color: Olive;">[</span><span style="color: Maroon;">1</span><span style="color: Olive;">])</span><span style="color: Gray;"> === </span><span style="color: Green;">false</span><span style="color: Gray;"> || </span><span style="color: Blue;">feof</span><span style="color: Olive;">(</span><span style="color: #00008b;">$pipes</span><span style="color: Olive;">[</span><span style="color: Maroon;">2</span><span style="color: Olive;">])</span><span style="color: Gray;"> === </span><span style="color: Green;">false</span><span style="color: Olive;">)</span><span style="color: Gray;"> &amp;&amp; </span><span style="color: #00008b;">$timeleft</span><span style="color: Gray;"> &gt; </span><span style="color: Maroon;">0</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">fclose</span><span style="color: Olive;">(</span><span style="color: #00008b;">$pipes</span><span style="color: Olive;">[</span><span style="color: Maroon;">1</span><span style="color: Olive;">])</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">fclose</span><span style="color: Olive;">(</span><span style="color: #00008b;">$pipes</span><span style="color: Olive;">[</span><span style="color: Maroon;">2</span><span style="color: Olive;">])</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Olive;">(</span><span style="color: #00008b;">$timeleft</span><span style="color: Gray;"> &lt;= </span><span style="color: Maroon;">0</span><span style="color: Olive;">)</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">proc_terminate</span><span style="color: Olive;">(</span><span style="color: #00008b;">$process</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$stderr_str</span><span style="color: Gray;"> = </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">操作已超时(</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">.</span><span style="color: #00008b;">$timeout</span><span style="color: Gray;">.</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">秒)</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Green;">isset</span><span style="color: Olive;">(</span><span style="color: #00008b;">$err</span><span style="color: Olive;">)</span><span style="color: Gray;"> &amp;&amp; </span><span style="color: #00008b;">$err</span><span style="color: Gray;"> === </span><span style="color: Green;">true</span><span style="color: Olive;">){</span><span style="color: Gray;">&nbsp; </span><span style="color: #ffa500;">//这种情况的出现是通过信号发送中断时产生</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">proc_terminate</span><span style="color: Olive;">(</span><span style="color: #00008b;">$process</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$stderr_str</span><span style="color: Gray;"> = </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">操作被用户取消</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">proc_close</span><span style="color: Olive;">(</span><span style="color: #00008b;">$process</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">return</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">true</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; </span><span style="color: Green;">else</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">return</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">false</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
</ol></div>
<p>stream_select 果然很强大&#8230;异步的读取输出，解决执行超时的问题。另外这种方式还可以防止输出堵死缓存。例如如果将上述获取输出的代码改成</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: #ffa500;">// stdout</span></li>
<li><span style="color: #00008b;">$stdout</span><span style="color: Gray;"> = </span><span style="color: Blue;">stream_get_contents</span><span style="color: Olive;">(</span><span style="color: #00008b;">$pipes</span><span style="color: Olive;">[</span><span style="color: Maroon;">1</span><span style="color: Olive;">])</span><span style="color: Gray;">;</span></li>
<li><span style="color: Blue;">fclose</span><span style="color: Olive;">(</span><span style="color: #00008b;">$pipes</span><span style="color: Olive;">[</span><span style="color: Maroon;">1</span><span style="color: Olive;">])</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span></li>
<li><span style="color: #ffa500;">// stderr</span></li>
<li><span style="color: #00008b;">$stderr</span><span style="color: Gray;"> = </span><span style="color: Blue;">stream_get_contents</span><span style="color: Olive;">(</span><span style="color: #00008b;">$pipes</span><span style="color: Olive;">[</span><span style="color: Maroon;">2</span><span style="color: Olive;">])</span><span style="color: Gray;">;</span></li>
<li><span style="color: Blue;">fclose</span><span style="color: Olive;">(</span><span style="color: #00008b;">$pipes</span><span style="color: Olive;">[</span><span style="color: Maroon;">2</span><span style="color: Olive;">])</span><span style="color: Gray;">;</span></li>
</ol></div>
<p>有就可能造成缓存堵死，当然对这种情况的处理也可以通过fork子进程解决。</p>

<p><strong>相关文章:</strong></p>
<ul>
<li><a href="http://www.i2up.com/2011/09/14/php%e5%a4%9a%e8%bf%9b%e7%a8%8b%e6%97%b6%ef%bc%8c%e9%81%87%e5%88%b0mysql-has-gone-away%e7%9a%84%e8%a7%a3%e5%86%b3/">php多进程时，遇到mysql has gone away的解决</a></li>
<li><a href="http://www.i2up.com/2011/06/06/bind_textdomain_codeset-undefined/">bind_textdomain_codeset undefined</a></li>
<li><a href="http://www.i2up.com/2011/03/08/%e4%bd%bf%e7%94%a8apache-%e7%9a%84php-cgi%e6%97%b6%e9%81%87%e5%88%b0%e7%9a%84internal-server-error%e5%8f%af%e8%83%bd%e5%8e%9f%e5%9b%a0/">使用apache 的PHP cgi时遇到的Internal Server Error可能原因</a></li>
<li><a href="http://www.i2up.com/2011/01/30/php-json%e8%a7%a3%e6%9e%90%e7%9a%84%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a1%b9/">PHP json解析的注意事项</a></li>
<li><a href="http://www.i2up.com/2011/01/10/%e4%bd%bf%e7%94%a8cgi%e4%bd%9c%e4%b8%baphp%e8%bf%90%e8%a1%8c%e7%9a%84%e5%91%bd%e4%bb%a4%e9%9c%80%e8%a6%81%e6%b3%a8%e6%84%8f%e7%9a%84/">使用cgi作为php运行的命令需要注意的</a></li>
</ul><br />
]]></content:encoded>
			<wfw:commentRss>http://www.i2up.com/2011/04/21/php%e4%b8%ad%e6%8e%a7%e5%88%b6proc_open%e7%9a%84%e6%89%a7%e8%a1%8c%e6%97%b6%e9%97%b4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>bash for 循环时遇到空格的解决办法</title>
		<link>http://www.i2up.com/2011/04/12/bash-for-%e5%be%aa%e7%8e%af%e6%97%b6%e9%81%87%e5%88%b0%e7%a9%ba%e6%a0%bc%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/</link>
		<comments>http://www.i2up.com/2011/04/12/bash-for-%e5%be%aa%e7%8e%af%e6%97%b6%e9%81%87%e5%88%b0%e7%a9%ba%e6%a0%bc%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/#comments</comments>
		<pubDate>Tue, 12 Apr 2011 05:29:04 +0000</pubDate>
		<dc:creator>YuYii</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>

		<guid isPermaLink="false">http://www.exp2up.com/?p=590</guid>
		<description><![CDATA[分两种情况: 1. 目录的遍历时,文件名中含有空格 如果用 for i in `ls directory` &#8230; 会有问题 应改用 cd directory &#38;&#38; for i in * &#8230; 2. 遍历文件中的行时,行中含有空格 这种情况有2个办法,一个是用while替换 cat file.txt &#124;while read line &#8230; line是需要输出的行内容 另外个办法仍然用for ,使用IFS IFS_old=$IFS #将原IFS值保存，以便用完后恢复 IFS=$’\n’ #更改IFS值为$’\n’ for line in `cat file.txt` ... 相关文章: vsftpd 500 OOPS: cannot change directory tar包文件名乱码的处理 使用sort删除重复行 配置openvpn 解决SSH tunnel连接后无法显示网页的问题]]></description>
			<content:encoded><![CDATA[<p>分两种情况:</p>
<p>1. 目录的遍历时,文件名中含有空格</p>
<p>如果用 for i in `ls directory` &#8230; 会有问题</p>
<p>应改用 cd directory &amp;&amp; for i in * &#8230;</p>
<p>2. 遍历文件中的行时,行中含有空格</p>
<p>这种情况有2个办法,一个是用while替换</p>
<p>cat file.txt |while read line &#8230; line是需要输出的行内容</p>
<p>另外个办法仍然用for ,使用IFS</p>
<pre>IFS_old=$IFS      #将原IFS值保存，以便用完后恢复
IFS=$’\n’         #更改IFS值为$’\n’
for line in `cat file.txt` ...</pre>

<p><strong>相关文章:</strong></p>
<ul>
<li><a href="http://www.i2up.com/2011/04/07/vsftpd-500-oops-cannot-change-directory/">vsftpd 500 OOPS: cannot change directory</a></li>
<li><a href="http://www.i2up.com/2011/03/28/tar%e5%8c%85%e6%96%87%e4%bb%b6%e5%90%8d%e4%b9%b1%e7%a0%81%e7%9a%84%e5%a4%84%e7%90%86/">tar包文件名乱码的处理</a></li>
<li><a href="http://www.i2up.com/2011/01/27/%e4%bd%bf%e7%94%a8sort%e5%88%a0%e9%99%a4%e9%87%8d%e5%a4%8d%e8%a1%8c/">使用sort删除重复行</a></li>
<li><a href="http://www.i2up.com/2010/08/19/%e9%85%8d%e7%bd%aeopenvpn/">配置openvpn</a></li>
<li><a href="http://www.i2up.com/2010/07/13/%e8%a7%a3%e5%86%b3ssh-tunnel%e8%bf%9e%e6%8e%a5%e5%90%8e%e6%97%a0%e6%b3%95%e6%98%be%e7%a4%ba%e7%bd%91%e9%a1%b5%e7%9a%84%e9%97%ae%e9%a2%98/">解决SSH tunnel连接后无法显示网页的问题</a></li>
</ul><br />
]]></content:encoded>
			<wfw:commentRss>http://www.i2up.com/2011/04/12/bash-for-%e5%be%aa%e7%8e%af%e6%97%b6%e9%81%87%e5%88%b0%e7%a9%ba%e6%a0%bc%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>vsftpd 500 OOPS: cannot change directory</title>
		<link>http://www.i2up.com/2011/04/07/vsftpd-500-oops-cannot-change-directory/</link>
		<comments>http://www.i2up.com/2011/04/07/vsftpd-500-oops-cannot-change-directory/#comments</comments>
		<pubDate>Thu, 07 Apr 2011 09:53:30 +0000</pubDate>
		<dc:creator>YuYii</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[vsftpd]]></category>

		<guid isPermaLink="false">http://www.exp2up.com/?p=588</guid>
		<description><![CDATA[用的是虚拟用户加chroot的方式做的 顺带贴下配置信息 # disables anonymous FTP anonymous_enable=NO &#160; # enables non-anonymous FTP local_enable=YES &#160; # activates virtual users guest_enable=YES #guest_username=ftp &#160; # virtual users to use local privs, not anon privs virtual_use_local_privs=YES &#160; # enables uploads and new directories write_enable=YES &#160; # disable downloads download_enable=NO &#160; # the PAM file used by authentication of virtual [...]]]></description>
			<content:encoded><![CDATA[<p>用的是虚拟用户加chroot的方式做的</p>
<p>顺带贴下配置信息</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"># disables anonymous FTP</li>
<li>anonymous_enable=NO</li>
<li>&nbsp;</li>
<li># enables non-anonymous FTP</li>
<li>local_enable=YES</li>
<li>&nbsp;</li>
<li># activates virtual users</li>
<li>guest_enable=YES</li>
<li>#guest_username=ftp</li>
<li>&nbsp;</li>
<li># virtual users to use local privs, not anon privs</li>
<li>virtual_use_local_privs=YES</li>
<li>&nbsp;</li>
<li># enables uploads and new directories</li>
<li>write_enable=YES</li>
<li>&nbsp;</li>
<li># disable downloads</li>
<li>download_enable=NO</li>
<li>&nbsp;</li>
<li># the PAM file used by authentication of virtual uses</li>
<li>pam_service_name=vsftpd-virtual</li>
<li>&nbsp;</li>
<li># in conjunction with 'local_root',</li>
<li># specifies a home directory for each virtual user</li>
<li>user_sub_token=$USER</li>
<li>local_root=/home/pub/uploads/$USER</li>
<li>&nbsp;</li>
<li># the virtual user is restricted to the virtual FTP area</li>
<li>chroot_local_user=YES</li>
<li>&nbsp;</li>
<li># hides the FTP server user IDs and just display &quot;ftp&quot; in directory listings</li>
<li>hide_ids=YES</li>
<li>&nbsp;</li>
<li># runs vsftpd in standalone mode</li>
<li>listen=YES</li>
<li>&nbsp;</li>
<li># listens on this port for incoming FTP connections</li>
<li>listen_port=21</li>
<li>&nbsp;</li>
<li># the minimum port to allocate for PASV style data connections</li>
<li>pasv_min_port=62222</li>
<li>&nbsp;</li>
<li># the maximum port to allocate for PASV style data connections</li>
<li>pasv_max_port=63333</li></ol></div>
<p>网上搜到的2种解决办法均无效:</p>
<p>1. selinux的问题</p>
<p>2. 目录权限问题</p>
<p>我这里说下我的第3个问题,非常之愚蠢&#8230;</p>
<p>仔细检查配置文件里local_root那行最后有没多点空格或者注释什么,都给干掉!</p>

<p><strong>相关文章:</strong></p>
<ul>
<li><a href="http://www.i2up.com/2011/04/12/bash-for-%e5%be%aa%e7%8e%af%e6%97%b6%e9%81%87%e5%88%b0%e7%a9%ba%e6%a0%bc%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/">bash for 循环时遇到空格的解决办法</a></li>
<li><a href="http://www.i2up.com/2011/03/28/tar%e5%8c%85%e6%96%87%e4%bb%b6%e5%90%8d%e4%b9%b1%e7%a0%81%e7%9a%84%e5%a4%84%e7%90%86/">tar包文件名乱码的处理</a></li>
<li><a href="http://www.i2up.com/2011/01/27/%e4%bd%bf%e7%94%a8sort%e5%88%a0%e9%99%a4%e9%87%8d%e5%a4%8d%e8%a1%8c/">使用sort删除重复行</a></li>
<li><a href="http://www.i2up.com/2010/08/19/%e9%85%8d%e7%bd%aeopenvpn/">配置openvpn</a></li>
<li><a href="http://www.i2up.com/2010/07/13/%e8%a7%a3%e5%86%b3ssh-tunnel%e8%bf%9e%e6%8e%a5%e5%90%8e%e6%97%a0%e6%b3%95%e6%98%be%e7%a4%ba%e7%bd%91%e9%a1%b5%e7%9a%84%e9%97%ae%e9%a2%98/">解决SSH tunnel连接后无法显示网页的问题</a></li>
</ul><br />
]]></content:encoded>
			<wfw:commentRss>http://www.i2up.com/2011/04/07/vsftpd-500-oops-cannot-change-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>pysvn checkout时convert UTF8失败</title>
		<link>http://www.i2up.com/2011/03/28/pysvn-checkout%e6%97%b6convert-utf8%e5%a4%b1%e8%b4%a5/</link>
		<comments>http://www.i2up.com/2011/03/28/pysvn-checkout%e6%97%b6convert-utf8%e5%a4%b1%e8%b4%a5/#comments</comments>
		<pubDate>Mon, 28 Mar 2011 02:57:45 +0000</pubDate>
		<dc:creator>YuYii</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[pysvn]]></category>

		<guid isPermaLink="false">http://www.exp2up.com/?p=584</guid>
		<description><![CDATA[通过设置python的locale即可,和bash处理方式是一样的. 另外补一下bash中的处理是用export方式做的. import locale &#160; language_code, encoding = locale.getdefaultlocale() if&#160;language_code is None: language_code = 'en_GB' if&#160;encoding is None: encoding = 'UTF-8' if&#160;encoding.lower() == 'utf': encoding = 'UTF-8' locale.setlocale(&#160;locale.LC_ALL, '%s.%s' % (language_code, encoding)) 相关文章: 关于位操作的一点小心得 twisted中发送二进制数据 Python处理Last-Modified 关于闭包的理解 python写了个简单的个税计算器基于命令行]]></description>
			<content:encoded><![CDATA[<p>通过设置python的locale即可,和bash处理方式是一样的. 另外补一下bash中的处理是用export方式做的.</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Green;">import</span><span style="color: Gray;"> </span><span style="color: Blue;">locale</span></li>
<li><span style="color: Gray;">&nbsp;</span></li>
<li><span style="color: Blue;">language_code</span><span style="color: Gray;">, </span><span style="color: Blue;">encoding</span><span style="color: Gray;"> = </span><span style="color: Blue;">locale</span><span style="color: Gray;">.</span><span style="color: Blue;">getdefaultlocale</span><span style="color: Olive;">()</span></li>
<li><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">language_code</span><span style="color: Gray;"> </span><span style="color: Green;">is</span><span style="color: Gray;"> </span><span style="color: Green;">None</span><span style="color: Gray;">:</span></li>
<li><span style="color: Blue;">language_code</span><span style="color: Gray;"> = </span><span style="color: #8b0000;">'</span><span style="color: Red;">en_GB</span><span style="color: #8b0000;">'</span></li>
<li><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">encoding</span><span style="color: Gray;"> </span><span style="color: Green;">is</span><span style="color: Gray;"> </span><span style="color: Green;">None</span><span style="color: Gray;">:</span></li>
<li><span style="color: Blue;">encoding</span><span style="color: Gray;"> = </span><span style="color: #8b0000;">'</span><span style="color: Red;">UTF-8</span><span style="color: #8b0000;">'</span></li>
<li><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">encoding</span><span style="color: Gray;">.</span><span style="color: Blue;">lower</span><span style="color: Olive;">()</span><span style="color: Gray;"> == </span><span style="color: #8b0000;">'</span><span style="color: Red;">utf</span><span style="color: #8b0000;">'</span><span style="color: Gray;">:</span></li>
<li><span style="color: Blue;">encoding</span><span style="color: Gray;"> = </span><span style="color: #8b0000;">'</span><span style="color: Red;">UTF-8</span><span style="color: #8b0000;">'</span></li>
<li><span style="color: Blue;">locale</span><span style="color: Gray;">.</span><span style="color: Blue;">setlocale</span><span style="color: Olive;">(</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">locale</span><span style="color: Gray;">.</span><span style="color: Blue;">LC_ALL</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">%s.%s</span><span style="color: #8b0000;">'</span><span style="color: Gray;"> % </span><span style="color: Olive;">(</span><span style="color: Blue;">language_code</span><span style="color: Gray;">, </span><span style="color: Blue;">encoding</span><span style="color: Olive;">))</span></li></ol></div>

<p><strong>相关文章:</strong></p>
<ul>
<li><a href="http://www.i2up.com/2009/08/08/%e5%85%b3%e4%ba%8e%e4%bd%8d%e6%93%8d%e4%bd%9c%e7%9a%84%e4%b8%80%e7%82%b9%e5%b0%8f%e5%bf%83%e5%be%97/">关于位操作的一点小心得</a></li>
<li><a href="http://www.i2up.com/2009/08/07/twisted%e4%b8%ad%e5%8f%91%e9%80%81%e4%ba%8c%e8%bf%9b%e5%88%b6%e6%95%b0%e6%8d%ae/">twisted中发送二进制数据</a></li>
<li><a href="http://www.i2up.com/2009/08/04/python%e5%a4%84%e7%90%86last-modified/">Python处理Last-Modified</a></li>
<li><a href="http://www.i2up.com/2009/07/17/%e5%85%b3%e4%ba%8e%e9%97%ad%e5%8c%85%e7%9a%84%e7%90%86%e8%a7%a3/">关于闭包的理解</a></li>
<li><a href="http://www.i2up.com/2009/05/04/python%e5%86%99%e4%ba%86%e4%b8%aa%e7%ae%80%e5%8d%95%e7%9a%84%e4%b8%aa%e7%a8%8e%e8%ae%a1%e7%ae%97%e5%99%a8%e5%9f%ba%e4%ba%8e%e5%91%bd%e4%bb%a4%e8%a1%8c/">python写了个简单的个税计算器基于命令行</a></li>
</ul><br />
]]></content:encoded>
			<wfw:commentRss>http://www.i2up.com/2011/03/28/pysvn-checkout%e6%97%b6convert-utf8%e5%a4%b1%e8%b4%a5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>tar包文件名乱码的处理</title>
		<link>http://www.i2up.com/2011/03/28/tar%e5%8c%85%e6%96%87%e4%bb%b6%e5%90%8d%e4%b9%b1%e7%a0%81%e7%9a%84%e5%a4%84%e7%90%86/</link>
		<comments>http://www.i2up.com/2011/03/28/tar%e5%8c%85%e6%96%87%e4%bb%b6%e5%90%8d%e4%b9%b1%e7%a0%81%e7%9a%84%e5%a4%84%e7%90%86/#comments</comments>
		<pubDate>Mon, 28 Mar 2011 02:50:07 +0000</pubDate>
		<dc:creator>YuYii</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[乱码]]></category>

		<guid isPermaLink="false">http://www.exp2up.com/?p=581</guid>
		<description><![CDATA[在使用linux做tar包时,拿到win上解压很容易看到文件名是乱码的情况.但是在通过samba看的时候是正常的. 其实是samba本身就支持了utf8编码的处理,tar和zip是不支持的.另外7z这个程序是支持unicode编码处理的,所以如果Linux和win都有7z,可以考虑用这个传,不会产生文件名的乱码,无需再看下午的解决办法. 这种情况是因为linux上是utf-8的系统环境编码,win上是gbk的 解决有2个办法,要么服务器压缩的时候就处理,要么解压时候处理. 我这里直接在压缩时候就处理好,需要手动转文件名的编码.通过工具convmv这个命令(可通过yum方式安装一下) convmv -f UTF-8 -t GBK $tmp_target_path/ -r &#8211;notest 这个命令实现 其中 -f是原编码 -t是目标编码 -r递归处理目录 &#8211;notest是直接做替换,不加则提示哪些文件需要被转码 之后再做tar,到win上看就正常了 相关文章: bash for 循环时遇到空格的解决办法 vsftpd 500 OOPS: cannot change directory 使用sort删除重复行 配置openvpn 解决SSH tunnel连接后无法显示网页的问题]]></description>
			<content:encoded><![CDATA[<p>在使用linux做tar包时,拿到win上解压很容易看到文件名是乱码的情况.但是在通过samba看的时候是正常的.</p>
<p>其实是samba本身就支持了utf8编码的处理,tar和zip是不支持的.另外7z这个程序是支持unicode编码处理的,所以如果Linux和win都有7z,可以考虑用这个传,不会产生文件名的乱码,无需再看下午的解决办法.</p>
<p>这种情况是因为linux上是utf-8的系统环境编码,win上是gbk的</p>
<p>解决有2个办法,要么服务器压缩的时候就处理,要么解压时候处理.</p>
<p>我这里直接在压缩时候就处理好,需要手动转文件名的编码.通过工具convmv这个命令(可通过yum方式安装一下)</p>
<p>convmv -f UTF-8 -t GBK $tmp_target_path/ -r &#8211;notest 这个命令实现<br />
其中<br />
-f是原编码<br />
-t是目标编码<br />
-r递归处理目录<br />
&#8211;notest是直接做替换,不加则提示哪些文件需要被转码</p>
<p>之后再做tar,到win上看就正常了</p>

<p><strong>相关文章:</strong></p>
<ul>
<li><a href="http://www.i2up.com/2011/04/12/bash-for-%e5%be%aa%e7%8e%af%e6%97%b6%e9%81%87%e5%88%b0%e7%a9%ba%e6%a0%bc%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/">bash for 循环时遇到空格的解决办法</a></li>
<li><a href="http://www.i2up.com/2011/04/07/vsftpd-500-oops-cannot-change-directory/">vsftpd 500 OOPS: cannot change directory</a></li>
<li><a href="http://www.i2up.com/2011/01/27/%e4%bd%bf%e7%94%a8sort%e5%88%a0%e9%99%a4%e9%87%8d%e5%a4%8d%e8%a1%8c/">使用sort删除重复行</a></li>
<li><a href="http://www.i2up.com/2010/08/19/%e9%85%8d%e7%bd%aeopenvpn/">配置openvpn</a></li>
<li><a href="http://www.i2up.com/2010/07/13/%e8%a7%a3%e5%86%b3ssh-tunnel%e8%bf%9e%e6%8e%a5%e5%90%8e%e6%97%a0%e6%b3%95%e6%98%be%e7%a4%ba%e7%bd%91%e9%a1%b5%e7%9a%84%e9%97%ae%e9%a2%98/">解决SSH tunnel连接后无法显示网页的问题</a></li>
</ul><br />
]]></content:encoded>
			<wfw:commentRss>http://www.i2up.com/2011/03/28/tar%e5%8c%85%e6%96%87%e4%bb%b6%e5%90%8d%e4%b9%b1%e7%a0%81%e7%9a%84%e5%a4%84%e7%90%86/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

