<?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>zeevin&#039;s blog</title>
	<atom:link href="http://www.zeevin.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.zeevin.com</link>
	<description>do the best!</description>
	<lastBuildDate>Fri, 10 Feb 2012 19:48:36 +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>js正则表达式表单验证</title>
		<link>http://www.zeevin.com/201202156.html</link>
		<comments>http://www.zeevin.com/201202156.html#comments</comments>
		<pubDate>Fri, 10 Feb 2012 19:48:36 +0000</pubDate>
		<dc:creator>zeevin</dc:creator>
				<category><![CDATA[PHP/Python/C]]></category>
		<category><![CDATA[其它相关]]></category>

		<guid isPermaLink="false">http://www.zeevin.com/?p=156</guid>
		<description><![CDATA[&#60;!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&#62; &#60;html xmlns=”http://www.w3.org/1999/xhtml”&#62; &#60;head&#62; &#60;meta http-equiv=”Content-Type” content=”text/html; charset=utf-8&#8243; /&#62; &#60;title&#62;js正则表达式匹配demo&#60;/title&#62; &#60;script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js”&#62;&#60;/script&#62; &#60;script type=”application/javascript”&#62; $(document).ready(function(){ /* 设置js正则表达式匹配规则,可以随意扩展,idcard,phone,num,required,alpha是验证规则名称，通过在相应的input字段添加validator属性生效。 比如validator=&#8217;alpha&#8217;,即为验证是否是字母，多个规则用&#8217;&#124;'连接，比如：validator=”required&#124;alpha&#124;upcase” 表示该字段不能为空、必须是字母，并且首字母大写。 下面的validate对象就是相应的规则定义。 */ var validate = new Array(); validate['idcard']= new Array(/^(\d{14}&#124;\d{17})(\d&#124;[Xx])$/,&#8217;格式不正确。&#8217;);//匹配身份证号码 validate['phone']= new Array(/(^1\d{10}$)&#124;(^\d{7,8}$)/,&#8217;电话号码格式不对。&#8217;);//电话号码只能是7或者8位数字 validate['num']= new Array(/^\d+$/,&#8217;不是数字&#8217;); //匹配数字 validate['required']= new Array(/^.+$/,&#8217;不能为空&#8217;);//是否为空 validate['alpha']= new Array(/^[a-zA-Z]+$/,&#8217;只能是字母&#8217;);//必须是字母 validate['upcase']= new Array(/^[A-Z]{1}/,&#8217;第一个字母要大写&#8217;); /* 促发验证规则 */ [...]]]></description>
			<content:encoded><![CDATA[<p>&lt;!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;<br />
&lt;html xmlns=”http://www.w3.org/1999/xhtml”&gt;<br />
&lt;head&gt;<br />
&lt;meta http-equiv=”Content-Type” content=”text/html; charset=utf-8&#8243; /&gt;<br />
&lt;title&gt;js正则表达式匹配demo&lt;/title&gt;<br />
&lt;script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js”&gt;&lt;/script&gt;<br />
&lt;script type=”application/javascript”&gt;<br />
$(document).ready(function(){<br />
/*<br />
设置js正则表达式匹配规则,可以随意扩展,idcard,phone,num,required,alpha是验证规则名称，通过在相应的input字段添加validator属性生效。<br />
比如validator=&#8217;alpha&#8217;,即为验证是否是字母，多个规则用&#8217;|'连接，比如：validator=”required|alpha|upcase”<br />
表示该字段不能为空、必须是字母，并且首字母大写。<br />
下面的validate对象就是相应的规则定义。<br />
*/<br />
var validate = new Array();<br />
validate['idcard']= new Array(/^(\d{14}|\d{17})(\d|[Xx])$/,&#8217;格式不正确。&#8217;);//匹配身份证号码<br />
validate['phone']= new Array(/(^1\d{10}$)|(^\d{7,8}$)/,&#8217;电话号码格式不对。&#8217;);//电话号码只能是7或者8位数字<br />
validate['num']= new Array(/^\d+$/,&#8217;不是数字&#8217;); //匹配数字<br />
validate['required']= new Array(/^.+$/,&#8217;不能为空&#8217;);//是否为空<br />
validate['alpha']= new Array(/^[a-zA-Z]+$/,&#8217;只能是字母&#8217;);//必须是字母<br />
validate['upcase']= new Array(/^[A-Z]{1}/,&#8217;第一个字母要大写&#8217;);</p>
<p>/*<br />
促发验证规则<br />
*/<br />
$(“#csub”).click(function(){</p>
<p>//验证之前先清空所有的提示,要进行验证的字段class必须加上myv;<br />
$(“.myv”).next().html(“”);</p>
<p>//下面是对每个字段分别进行循环验证；比如要求身高不能为空且必须是数字；<br />
$(“.myv”).each(function(){<br />
//拆分当前对象使用的验证规则<br />
$tmp = $(this).attr(“validator”).split(“|”);<br />
//取得当前表单的值，按照指定的规则开始验证<br />
for($v in $tmp){<br />
//alert($tmp[$v]);<br />
if(!validate[$tmp[$v]][0].exec($(this).val())) $(this).next().html($(this).attr(“title”)+validate[$tmp[$v]][1]);<br />
}<br />
//下面的这些是为了使必填字段提示的更人性化。比如英文名要求是英文并且不能为空，如果这时字段为空提示不能为空而不提示”当前字段不是英文“，\<br />
//只有当这个字段不会空时才对比是否是英文。<br />
if($.trim($(this).val())==”){<br />
$count=0;<br />
for($t in $tmp){<br />
if($tmp[$t]==”required” )$count=1;<br />
else $(this).next().html(“”);<br />
}<br />
if($count)$(this).next().html($(this).attr(“title”)+validate['required'][1]);<br />
}<br />
});</p>
<p>})<br />
});<br />
&lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;form&gt;<br />
身份证号:&lt;input id=”cid” title=”身份证号码” name=”card” maxlength=”18&#8243; type=”text” validator=”idcard”/&gt;&lt;span&gt;&lt;/span&gt;&lt;br/&gt;<br />
电话号码：&lt;input id=”tel” title=”" name=”tel”  maxlength=”11&#8243; type=”text” validator=”required|phone”/&gt;&lt;span&gt;&lt;/span&gt;&lt;br/&gt;<br />
身高：&lt;input  title=”身高” validator=”num|required”/&gt;&lt;span&gt;&lt;/span&gt;&lt;br/&gt;<br />
英文名：&lt;input type=”text” title=”英文名” validator=”required|alpha|upcase”/&gt;&lt;span&gt;&lt;/span&gt;&lt;br/&gt;<br />
&lt;input id=”csub” type=”button” value=”sub” /&gt;<br />
&lt;/form&gt;<br />
&lt;body&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zeevin.com/201202156.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>solaris使用opencsw安装软件包</title>
		<link>http://www.zeevin.com/201112144.html</link>
		<comments>http://www.zeevin.com/201112144.html#comments</comments>
		<pubDate>Fri, 30 Dec 2011 09:03:23 +0000</pubDate>
		<dc:creator>zeevin</dc:creator>
				<category><![CDATA[Linux技术]]></category>
		<category><![CDATA[opencsw]]></category>
		<category><![CDATA[solaris]]></category>

		<guid isPermaLink="false">http://www.zeevin.com/?p=144</guid>
		<description><![CDATA[在solaris下安装或者更新软件通常有3种方法： 1.下载源代码编译安装。 2.从sunfreeware.com下载pkg包，使用pkgadd安装。 3.下载pkg-get工具（类似于redhat的yum），在线更新软件包，这种方法其实是对第二种方法的自动化封装实现。 很多时候，我们要安装的软件依赖与其他一些的包，这是我们可以综合使用上面的三种方法： ①对于一些小的或者我们不打算定制安装的包使用方法2或者3安装，更快捷。 ②对于需要定制安装或者sunfreeware.com中未提供的包采用方法1安装。不幸的是，仍然有 一些软件包无法使用SunStutio（solaris提供的gcc编辑器）进行编译。通常是因为软件包在编译时只考虑gun gcc，没考虑SunStutio。这时我们必须使用gun gcc编译，我们需要设置以下环境变量： export CPP=”/usr/sfw/bin/gcc -E” export CC=/usr/sfw/bin/gcc export CXX=/usr/sfw/bin/g++ 然后再编译。但是问题又来了，我们的依赖包也许还要依赖其他的包，我们可能需要手工编译很多包最终才能成功！ so，opencsw降临! 她致力于解决这些问题。opencsw提供pkgutil包管理工具，通过在线的方式更新软件包，同时解决软件的依赖问题。 我们只需要两步设置： ①安装opencsw： pkgadd -d http://get.opencsw.org/now ，默认安装在/opt/csw/内 ②使用pkgutil安装软件包，比如：/opt/csw/bin/pkgutil &#8211;install libmagic,默认安装到/opt/csw/lib/下，然后建立相关库到/usr/local/lib/的链接或者添加/opt/csw/lib/到动态链接库环境变量.到这里一切ok，我们可以继续编译安装软件。 不得不说opencsw提供了一种更简单、方便的方式安装某些软件。 目前支持的软件和包列表：http://www.opencsw.org/get-it/packages/ 其他的一些设置可以到官方网站查询：http://www.opencsw.org/]]></description>
			<content:encoded><![CDATA[<p>在solaris下安装或者更新软件通常有3种方法：</p>
<blockquote><p>1.下载源代码编译安装。<br />
2.从sunfreeware.com下载pkg包，使用pkgadd安装。<br />
3.下载pkg-get工具（类似于redhat的yum），在线更新软件包，这种方法其实是对第二种方法的自动化封装实现。</p></blockquote>
<p>很多时候，我们要安装的软件依赖与其他一些的包，这是我们可以综合使用上面的三种方法：<br />
①对于一些小的或者我们不打算定制安装的包使用方法2或者3安装，更快捷。<br />
②对于需要定制安装或者sunfreeware.com中未提供的包采用方法1安装。不幸的是，仍然有<br />
一些软件包无法使用SunStutio（solaris提供的gcc编辑器）进行编译。通常是因为软件包在编译时只考虑gun gcc，没考虑SunStutio。这时我们必须使用gun gcc编译，我们需要设置以下环境变量：</p>
<blockquote><p>export CPP=”/usr/sfw/bin/gcc -E”<br />
export CC=/usr/sfw/bin/gcc<br />
export CXX=/usr/sfw/bin/g++</p></blockquote>
<p>然后再编译。但是问题又来了，我们的依赖包也许还要依赖其他的包，我们可能需要手工编译很多包最终才能成功！</p>
<p>so，opencsw降临!</p>
<p>她致力于解决这些问题。opencsw提供pkgutil包管理工具，通过在线的方式更新软件包，同时解决软件的依赖问题。<br />
我们只需要两步设置：</p>
<blockquote><p>①安装opencsw： pkgadd -d http://get.opencsw.org/now ，默认安装在/opt/csw/内<br />
②使用pkgutil安装软件包，比如：/opt/csw/bin/pkgutil &#8211;install libmagic,默认安装到/opt/csw/lib/下，然后建立相关库到/usr/local/lib/的链接或者添加/opt/csw/lib/到动态链接库环境变量.到这里一切ok，我们可以继续编译安装软件。</p></blockquote>
<p>不得不说opencsw提供了一种更简单、方便的方式安装某些软件。</p>
<p>目前支持的软件和包列表：http://www.opencsw.org/get-it/packages/<br />
其他的一些设置可以到官方网站查询：http://www.opencsw.org/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zeevin.com/201112144.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>c语言指针学习一</title>
		<link>http://www.zeevin.com/201112141.html</link>
		<comments>http://www.zeevin.com/201112141.html#comments</comments>
		<pubDate>Mon, 26 Dec 2011 15:06:40 +0000</pubDate>
		<dc:creator>zeevin</dc:creator>
				<category><![CDATA[PHP/Python/C]]></category>
		<category><![CDATA[c]]></category>

		<guid isPermaLink="false">http://www.zeevin.com/?p=141</guid>
		<description><![CDATA[#include &#60;stdio.h&#62; void pointer1() { /* * p为int型的指针，p++只跳到数组的下一个元素，数组名a代表&#38;a[0]，即代表第一个元素的起始地址 * 统一数组在内存中的地址是连续的 */ int a[10],*p,i; for(i=0;i&#60;10;i++) { scanf(“%d”,&#38;a[i]); } for(i=1,p=a;p&#60;a+10;p++,i++) { printf(“a[%d] 的值是:%d，内存地址是：%d\n”,i,*p,p); } }]]></description>
			<content:encoded><![CDATA[<p>#include &lt;stdio.h&gt;<br />
void pointer1()<br />
{<br />
/*<br />
* p为int型的指针，p++只跳到数组的下一个元素，数组名a代表&amp;a[0]，即代表第一个元素的起始地址<br />
* 统一数组在内存中的地址是连续的<br />
*/<br />
int a[10],*p,i;<br />
for(i=0;i&lt;10;i++)<br />
{<br />
scanf(“%d”,&amp;a[i]);<br />
}<br />
for(i=1,p=a;p&lt;a+10;p++,i++)<br />
{<br />
printf(“a[%d] 的值是:%d，内存地址是：%d\n”,i,*p,p);<br />
}<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zeevin.com/201112141.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php截取字符串乱码问题</title>
		<link>http://www.zeevin.com/201112133.html</link>
		<comments>http://www.zeevin.com/201112133.html#comments</comments>
		<pubDate>Sun, 18 Dec 2011 11:40:07 +0000</pubDate>
		<dc:creator>zeevin</dc:creator>
				<category><![CDATA[PHP/Python/C]]></category>

		<guid isPermaLink="false">http://www.zeevin.com/?p=133</guid>
		<description><![CDATA[substr()函数用来截取字符串，是按字节截取，mb_substr()是按照字符截取，并且可以指定编码（以utf-8为例）。 比如： $str = “测试A4abcd截取字符串乱码问题！”; $sub = substr($str, 0,5); var_dump ($sub); echo bin2hex($sub); 因为utf-8编码中一个汉字占三个字节，例子中截取了第一个汉字和第二个汉字的前两个字节，共5个字节。第二个字节乱码。而采用mb_substr()则不会出现乱码： 类似的还有很会出现乱码的函数。php提供了一批多字节处理函数（mb_开头），用来处理汉字等多字节编码。 比如使用mb_split()代替explode()。 &#160; &#160; 说明 string substr ( string $string , int $start [, int $length ] ) 返回字符串 string 由 start 和 length 参数指定的子字符串。]]></description>
			<content:encoded><![CDATA[<div>
<p>substr()函数用来截取字符串，是按字节截取，mb_substr()是按照字符截取，并且可以指定编码（以utf-8为例）。</p>
<p>比如：</p>
<p>$str = “测试A4abcd截取字符串乱码问题！”;<br />
$sub = substr($str, 0,5);<br />
var_dump ($sub);<br />
echo bin2hex($sub);</p>
<p><a href="http://www.zeevin.com/201112133.html/%e6%9c%aa%e5%91%bd%e5%90%8d" rel="attachment wp-att-134"><img class="alignnone size-full wp-image-134" title="mb_substr" src="http://www.zeevin.com/wp-content/uploads/2011/12/未命名.jpg" alt="" width="264" height="97" /></a><br />
因为utf-8编码中一个汉字占三个字节，例子中截取了第一个汉字和第二个汉字的前两个字节，共5个字节。第二个字节乱码。而采用mb_substr()则不会出现乱码：</p>
<p><a href="http://www.zeevin.com/wp-content/uploads/2011/12/mb_substr.jpg"><img class="alignnone size-full wp-image-137" title="mb_substr" src="http://www.zeevin.com/wp-content/uploads/2011/12/mb_substr.jpg" alt="" width="250" height="119" /></a></p>
<p>类似的还有很会出现乱码的函数。php提供了一批多字节处理函数（mb_开头），用来处理汉字等多字节编码。</p>
<p>比如使用mb_split()代替explode()。</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</div>
<div id="refsect1-function.substr-description">
<h3>说明</h3>
<div>string <strong>substr</strong> ( string <tt>$string</tt> , int <tt>$start</tt> [, int <tt>$length</tt> ] )</div>
<p>返回字符串 <em><tt>string</tt></em> 由 <em><tt>start</tt></em> 和 <em><tt>length</tt></em> 参数指定的子字符串。</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.zeevin.com/201112133.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php curl获取https内容</title>
		<link>http://www.zeevin.com/201112127.html</link>
		<comments>http://www.zeevin.com/201112127.html#comments</comments>
		<pubDate>Sat, 03 Dec 2011 07:16:49 +0000</pubDate>
		<dc:creator>zeevin</dc:creator>
				<category><![CDATA[PHP/Python/C]]></category>

		<guid isPermaLink="false">http://www.zeevin.com/?p=127</guid>
		<description><![CDATA[$url = &#8216;https://www.alipay.com&#8217;; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_FAILONERROR, 0); $data = curl_exec($ch); curl_close($ch); echo ($data);]]></description>
			<content:encoded><![CDATA[<p>$url = &#8216;https://www.alipay.com&#8217;;<br />
$ch = curl_init($url);<br />
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br />
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);<br />
curl_setopt($ch, CURLOPT_FAILONERROR, 0);</p>
<p>$data = curl_exec($ch);<br />
curl_close($ch);<br />
echo ($data);</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zeevin.com/201112127.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSL negotiation failed: SSL disabled due to library version mismatch</title>
		<link>http://www.zeevin.com/201112124.html</link>
		<comments>http://www.zeevin.com/201112124.html#comments</comments>
		<pubDate>Fri, 02 Dec 2011 03:20:40 +0000</pubDate>
		<dc:creator>zeevin</dc:creator>
				<category><![CDATA[Linux技术]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://www.zeevin.com/?p=124</guid>
		<description><![CDATA[svn: PROPFIND of : SSL negotiation failed: SSL disabled due to library version mismatch () There were lots of threads in many forums that suggested re-emerging openssl and svn, but that didn&#8217;t do it for me. Finally I stumbled upon a thread that suggested something I wouldn&#8217;t have thought of: What I finally had to [...]]]></description>
			<content:encoded><![CDATA[<p>svn: PROPFIND of
<path>: SSL negotiation failed: SSL disabled due to library version mismatch (<URL>)</p>
<p>There were lots of threads in many forums that suggested re-emerging openssl and svn, but that didn&#8217;t do it for me.</p>
<p>Finally I stumbled upon a thread that suggested something I wouldn&#8217;t have thought of: What I finally had to do was re-emerge neon. Once I got the latest version of neon, all was well. Though it wasn&#8217;t immediately obvious. I would think that if it was that important of a dependancy, emerging either openssl or subversion would have noticed I had an old, crufty version of it. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.zeevin.com/201112124.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>腾讯微博oauth认证</title>
		<link>http://www.zeevin.com/201111107.html</link>
		<comments>http://www.zeevin.com/201111107.html#comments</comments>
		<pubDate>Sat, 26 Nov 2011 13:46:13 +0000</pubDate>
		<dc:creator>zeevin</dc:creator>
				<category><![CDATA[PHP/Python/C]]></category>

		<guid isPermaLink="false">http://www.zeevin.com/?p=107</guid>
		<description><![CDATA[腾讯微博api采用OAuth 1.0a进行授权认证，除了采用官方提供的php-sdk进行开发外还可以使用php语言本身的oauth扩展。 首先下载安装oauth扩展。 windows版本下载地址：http://downloads.php.net/pierre/php_oauth-1.1.1-dev-5.3-nts-vc9-x86.zip linux版本使用pecl下载安装： pecl install oauth 我们需要三个页面：ten.php是跳转页面，跳转到授权页面，back.php是回调地址，用户授权完成后会跳，demo.php演示页面，用得到的授权信息发送一条微博。 ten.php &#60;?php $req_url = 'https://open.t.qq.com/cgi-bin/request_token'; $authurl = 'https://open.t.qq.com/cgi-bin/authorize'; $acc_url = 'https://open.t.qq.com/cgi-bin/access_token'; $api_url = 'http://open.t.qq.com/api/t/add'; $conskey = 'aaaaaae'; $conssec = 'aaaaaaa'; $oauth = new OAuth&#40;$conskey,$conssec,OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_URI&#41;; $oauth = disableSSLChecks&#40;&#41;; $oauth-&#62;setNonce&#40;&#40;rand&#40;&#41;&#41;&#41;; $oauth-&#62;setTimestamp&#40;time&#40;&#41;&#41;; $requestToken = $oauth-&#62;getRequestToken&#40;$req_url,'http://localhost/back.php'&#41;; $_SESSION&#91;'oauth_token'&#93;=$requestToken&#91;'oauth_token'&#93;; $_SESSION&#91;'oauth_token_secret'&#93;=$requestToken&#91;'oauth_token_secret'&#93;; header&#40;&#34;Location: $authurl&#34;.'?oauth_token='.$requestToken&#91;'oauth_token'&#93;&#41;; back.php &#60;?php $req_url = 'https://open.t.qq.com/cgi-bin/request_token'; $authurl = 'https://open.t.qq.com/cgi-bin/authorize'; $acc_url = [...]]]></description>
			<content:encoded><![CDATA[<p>腾讯微博api采用OAuth 1.0a进行授权认证，除了采用官方提供的php-sdk进行开发外还可以使用php语言本身的oauth扩展。<br />
首先下载安装oauth扩展。<br />
windows版本下载地址：http://downloads.php.net/pierre/php_oauth-1.1.1-dev-5.3-nts-vc9-x86.zip</p>
<p>linux版本使用pecl下载安装：</p>
<p>pecl install oauth</p>
<p>我们需要三个页面：ten.php是跳转页面，跳转到授权页面，back.php是回调地址，用户授权完成后会跳，demo.php演示页面，用得到的授权信息发送一条微博。</p>
<p>ten.php</p>

<div class="wp_code"><div class="pre"><pre class="php" style="font-family:'Times New Roman',Garamond, Times;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$req_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'https://open.t.qq.com/cgi-bin/request_token'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$authurl</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'https://open.t.qq.com/cgi-bin/authorize'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$acc_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'https://open.t.qq.com/cgi-bin/access_token'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$api_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://open.t.qq.com/api/t/add'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conskey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'aaaaaae'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conssec</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'aaaaaaa'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$oauth</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> OAuth<span style="color: #009900;">&#40;</span><span style="color: #000088;">$conskey</span><span style="color: #339933;">,</span><span style="color: #000088;">$conssec</span><span style="color: #339933;">,</span>OAUTH_SIG_METHOD_HMACSHA1<span style="color: #339933;">,</span>OAUTH_AUTH_TYPE_URI<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$oauth</span> <span style="color: #339933;">=</span> disableSSLChecks<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$oauth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setNonce</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$oauth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTimestamp</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$requestToken</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$oauth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequestToken</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$req_url</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'http://localhost/back.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'oauth_token'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$requestToken</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'oauth_token'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'oauth_token_secret'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$requestToken</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'oauth_token_secret'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: <span style="color: #006699; font-weight: bold;">$authurl</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'?oauth_token='</span><span style="color: #339933;">.</span><span style="color: #000088;">$requestToken</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'oauth_token'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>back.php</p>

<div class="wp_code"><div class="pre"><pre class="php" style="font-family:'Times New Roman',Garamond, Times;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$req_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'https://open.t.qq.com/cgi-bin/request_token'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$authurl</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'https://open.t.qq.com/cgi-bin/authorize'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$acc_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'https://open.t.qq.com/cgi-bin/access_token'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$api_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://open.t.qq.com/api/t/add'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conskey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'aaaaaae'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conssec</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'aaaaaaa'</span><span style="color: #339933;">;</span>
<span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$oauth</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> OAuth<span style="color: #009900;">&#40;</span><span style="color: #000088;">$conskey</span><span style="color: #339933;">,</span><span style="color: #000088;">$conssec</span><span style="color: #339933;">,</span>OAUTH_SIG_METHOD_HMACSHA1<span style="color: #339933;">,</span>OAUTH_AUTH_TYPE_URI<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$oauth</span> <span style="color: #339933;">=</span> disableSSLChecks<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$oauth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setNonce</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$oauth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setToken</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$reqtoken</span><span style="color: #339933;">,</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'oauth_token_secret'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$accesstoken</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$oauth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAccessToken</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$acc_url</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span><span style="color: #000088;">$oauth_verfy</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//print_r($accesstoken);</span>
<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'access_token'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$accesstoken</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'access_token'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'access_token_secret'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$accesstoken</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'access_token_secret'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

<p>demo.php</p>

<div class="wp_code"><div class="pre"><pre class="php" style="font-family:'Times New Roman',Garamond, Times;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$req_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'https://open.t.qq.com/cgi-bin/request_token'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$authurl</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'https://open.t.qq.com/cgi-bin/authorize'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$acc_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'https://open.t.qq.com/cgi-bin/access_token'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$api_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://open.t.qq.com/api/t/add'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conskey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'aaaaaae'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conssec</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'aaaaaaa'</span><span style="color: #339933;">;</span>
<span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$oauth</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> OAuth<span style="color: #009900;">&#40;</span><span style="color: #000088;">$conskey</span><span style="color: #339933;">,</span><span style="color: #000088;">$conssec</span><span style="color: #339933;">,</span>OAUTH_SIG_METHOD_HMACSHA1<span style="color: #339933;">,</span>OAUTH_AUTH_TYPE_URI<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$oauth</span> <span style="color: #339933;">=</span> disableSSLChecks<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$oauth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setNonce</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$oauth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setToken</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$accesstoken</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'access_token'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #000088;">$accesstoken</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'access_token_secret'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$oauth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$api_url</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'content'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'pcre oauth test!'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'format'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'json'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'clientip'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'127.0.0.1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>OAUTH_HTTP_METHOD_POST<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$oauth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLastResponse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.zeevin.com/201111107.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>solaris 编译安装nginx+php5.3.8（php-fpm）</title>
		<link>http://www.zeevin.com/20111199.html</link>
		<comments>http://www.zeevin.com/20111199.html#comments</comments>
		<pubDate>Sat, 26 Nov 2011 09:30:20 +0000</pubDate>
		<dc:creator>zeevin</dc:creator>
				<category><![CDATA[PHP/Python/C]]></category>
		<category><![CDATA[web服务器]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php-fpm]]></category>

		<guid isPermaLink="false">http://www.zeevin.com/?p=99</guid>
		<description><![CDATA[历史记录： 2011-12-19 修改，添加 fastcgi_intercept_errors on;当请求一个不存在的php页面时原来返回空，添加后返回404错误。 php从5.3.3版本开始内置FPM（FastCGI 进程管理器），用于替换PHP FastCGI的大部分附加功能，对于高负载网站是非常有用的。 它的功能包括： 支持平滑停止/启动的高级进程管理功能； 可以工作于不同的uid/gid/chroot环境下，并监听不同的端口和使用不同的php.ini配置文件（可取代safe_mode的设置）； stdout 和 stderr 日志记录; 在发生意外情况的时候能够重新启动并缓存被破坏的opcode; 文件上传优化支持; “慢日志” &#8211; 记录脚本 (不仅记录文件名，还记录PHP backtrace信息，可以使用ptrace或者类似工具读取和分析远程进程的运行数据) 运行所导致的异常缓慢; fastcgi_finish_request() &#8211; 特殊功能：用于在请求完成和刷新数据后，继续在后台执行耗时的工作 (录入视频转换、统计处理等)； 动态/静态子进程产生; FPM带来的好处还远不止这些，在此种模式下php本身对apache和nginx等web服务器的依赖程度也更低，服务器软件主要起到请求转发的功能，即将用户的请求转发到FPM监听的端口，php处理后返回结果供web显示。因此选用更轻量级以及并发处理更高的nginx做web服务器成为首选。 &#160; 一下为本人在solaris10  x86机器上的安装记录： 1.下载并安装pkg-get工具： wget http://sunfreeware.com/BOLTpget.pkg pkgadd -d BOLTpget.pkg 2.在线更新php依赖库： pkg-get install gd-2.0.35 pkg-get install jpeg-8a pkg-get install libpng-1.2.10 pkg-get install libiconv-1.9.2 pkg-get install openssl-1.0.0e pkg-get [...]]]></description>
			<content:encoded><![CDATA[<p>历史记录：</p>
<p>2011-12-19 修改，添加 fastcgi_intercept_errors on;当请求一个不存在的php页面时原来返回空，添加后返回404错误。</p>
<p>php从5.3.3版本开始内置FPM（FastCGI 进程管理器），用于替换PHP FastCGI的大部分附加功能，对于高负载网站是非常有用的。</p>
<p>它的功能包括：</p>
<ul>
<li>支持平滑停止/启动的高级进程管理功能；</li>
<li>可以工作于不同的uid/gid/chroot环境下，并监听不同的端口和使用不同的php.ini配置文件（可取代safe_mode的设置）；</li>
<li>stdout 和 stderr 日志记录;</li>
<li>在发生意外情况的时候能够重新启动并缓存被破坏的opcode;</li>
<li>文件上传优化支持;</li>
<li>“慢日志” &#8211; 记录脚本 (不仅记录文件名，还记录PHP backtrace信息，可以使用ptrace或者类似工具读取和分析远程进程的运行数据) 运行所导致的异常缓慢;</li>
<li><strong>fastcgi_finish_request()</strong> &#8211; 特殊功能：用于在请求完成和刷新数据后，继续在后台执行耗时的工作 (录入视频转换、统计处理等)；</li>
<li>动态/静态子进程产生;</li>
</ul>
<p>FPM带来的好处还远不止这些，在此种模式下php本身对apache和nginx等web服务器的依赖程度也更低，服务器软件主要起到请求转发的功能，即将用户的请求转发到FPM监听的端口，php处理后返回结果供web显示。因此选用更轻量级以及并发处理更高的nginx做web服务器成为首选。</p>
<p>&nbsp;</p>
<p>一下为本人在solaris10  x86机器上的安装记录：</p>
<p>1.下载并安装pkg-get工具：<br />
wget http://sunfreeware.com/BOLTpget.pkg<br />
pkgadd -d BOLTpget.pkg<br />
2.在线更新php依赖库：<br />
pkg-get install gd-2.0.35<br />
pkg-get install jpeg-8a<br />
pkg-get install libpng-1.2.10<br />
pkg-get install libiconv-1.9.2<br />
pkg-get install openssl-1.0.0e<br />
pkg-get install curl-7.12.2 （此处curl版本不要装太高的）<br />
pkg-get install openldap-2.4.9<br />
pkg-get install sasl-2.1.25<br />
pkg-get install libnet<br />
pkg-get install zlib-1.2.5<br />
pkg-get install mhash-0.9.9.9<br />
pkg-get install gdbm-1.9.1<br />
pkg-get install libxml2-2.7.8<br />
3.下载安装freetype<br />
wget http://download.savannah.gnu.org/releases/freetype/freetype-2.3.5.tar.gz<br />
gunzip freetype-2.3.5.tar.gz<br />
tar -xvf freetype-2.3.5.tar<br />
cd freetype-2.3.5<br />
./configure &#8211;prefix=/usr/local/freetype<br />
make<br />
make install<br />
cd ../</p>
<p>4.下载安装libmcrypt<br />
wget http://down1.chinaunix.net/distfiles/libmcrypt-2.5.7.tar.gz<br />
gunzip  libmcrypt-2.5.7.tar.gz<br />
tar -xvf  libmcrypt-2.5.7.tar<br />
cd libmcrypt-2.5.7.<br />
./configure -–enable-dynamic-loading –-with-included-algos=”rijndael-128 arcfour stream cbc cfb”<br />
make<br />
make install<br />
cd ..</p>
<p>5.下载安装php5.3.8<br />
wget http://cn2.php.net/distributions/php-5.3.8.tar.gz<br />
gunzip php-5.3.8.tar.gz<br />
tar -xvf php-5.3.8.tar</p>
<p>6.下载nginx-1.0.10 稳定版</p>
<p>http://nginx.org/download/nginx-1.0.10.tar.gz</p>
<p>gunzip nginx-1.0.10.tar.gz<br />
tar -xvf  nginx-1.0.10.tar</p>
<p>建立服务器软件安装目录<br />
mkdir /usr/local/webserver<br />
创建网站目录<br />
/export/home/web/root<br />
创建web群组和web用户<br />
groupadd web<br />
useradd -d /export/home/web/root -g web web<br />
以fpm方式编译安装php5.3.8<br />
cd php-5.3.8<br />
&#8216;./configure&#8217; &#8216;&#8211;prefix=/usr/local/webserver/php&#8217; &#8216;&#8211;enable-fpm&#8217; &#8216;&#8211;with-mysql=mysqlnd&#8217; &#8216;&#8211;with-mysqli=mysqlnd&#8217; &#8216;&#8211;with-pdo-mysql=mysqlnd&#8217; &#8216;&#8211;with-gd&#8217; &#8216;&#8211;with-png-dir&#8217; &#8216;&#8211;with-jpeg-dir&#8217; &#8216;&#8211;with-iconv=/usr/local/lib&#8217; &#8216;&#8211;enable-mbstring&#8217; &#8216;&#8211;with-zlib&#8217; &#8216;&#8211;with-libxml-dir&#8217; &#8216;&#8211;enable-gd-native-ttf&#8217; &#8216;&#8211;with-openssl&#8217;  &#8216;&#8211;enable-pcntl&#8217; &#8216;&#8211;enable-sockets&#8217; &#8216;&#8211;with-ldap&#8217; &#8216;&#8211;with-ldap-sasl&#8217; &#8216;&#8211;with-xmlrpc&#8217; &#8216;&#8211;enable-zip&#8217; &#8216;&#8211;enable-soap&#8217; &#8216;–with-mcrypt=/usr/local/lib&#8217; &#8216;&#8211;with-freetype-dir=/usr/local/freetype/&#8217; &#8216;&#8211;with-curl&#8217; &#8216;&#8211;with-curlwrappers&#8217;</p>
<p>make<br />
make install<br />
查看php是否安装成功：<br />
/usr/local/webserver/php/bin/php -v<br />
提示:<br />
PHP 5.3.8 (cli) (built: Nov 25 2011 00:34:48)<br />
Copyright (c) 1997-2011 The PHP Group<br />
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies<br />
表示成功</p>
<p>复制php.ini配置文件<br />
cp php.ini-production /usr/local/webserver/php/lib/php.ini</p>
<p>设置php-fpm自启动<br />
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm<br />
chmod +x /etc/init.d/php-fpm<br />
复制php-fpm配置文件<br />
cp -r sapi/fpm/php-fpm.conf /usr/local/webserver/php/etc/<br />
编辑php-fpm配置文件：<br />
vi /usr/local/webserver/php/etc/php-fpm.conf<br />
查找并打开以下配置（去掉对应行首注释）<br />
pid = run/php-fpm.pid<br />
error_log = log/php-fpm.log<br />
log_level = notice 改为log_level = error<br />
emergency_restart_interval = 0 改为 emergency_restart_interval = 3d<br />
daemonize = yes<br />
listen = 127.0.0.1:9000 改为 listen = /tmp/php-cgi.sock<br />
listen.allowed_clients = 127.0.0.1<br />
user = nobody 改为 user = web<br />
group = nobody 改为 group = web<br />
pm.max_children = 150<br />
pm.start_servers = 45<br />
pm.min_spare_servers = 10<br />
pm.max_spare_servers = 100<br />
pm.max_requests = 1000<br />
保存并退出（各参数意思请查看文档注释）</p>
<p>启动php-fpm(也就是启动php)：<br />
/etc/init.d/php-fpm start</p>
<p>ps查看进程，查看php是否启动成功。</p>
<p>7.安装nginx<br />
首先更新pcre：<br />
pkg-get install pcre-8.13<br />
解压并安装nginx：<br />
cd nginx-1.0.10<br />
./configure &#8211;group=web &#8211;user=web &#8211;prefix=/usr/local/webserver/nginx &#8211;with-http_stub_status_module &#8211;with-http_ssl_module<br />
make &amp;&amp; make install</p>
<p>修改配置文件<br />
vi /usr/local/webserver/nginx/conf/nginx.conf，这是主配置文件，设置虚拟主机，php代理设置等,配置如下（示例）：<br />
#user  nobody;<br />
worker_processes  5;</p>
<p>#error_log  logs/error.log;<br />
#error_log  logs/error.log  notice;<br />
#error_log  logs/error.log  info;</p>
<p>pid        logs/nginx.pid;</p>
<p>worker_rlimit_nofile 65535;<br />
events {<br />
use epoll;<br />
worker_connections  65535;<br />
}</p>
<p>http {<br />
include       mime.types;<br />
default_type  application/octet-stream;</p>
<p>log_format  main  &#8216;$remote_addr &#8211; $remote_user [$time_local] “$request” &#8216;<br />
&#8216;$status $body_bytes_sent “$http_referer” &#8216;<br />
&#8216;”$http_user_agent” “$http_x_forwarded_for”&#8216;;</p>
<p>access_log  logs/access.log  main;</p>
<p>server_names_hash_bucket_size 128;<br />
client_header_buffer_size 32k;<br />
large_client_header_buffers 4 32k;<br />
client_max_body_size 8m;</p>
<p>sendfile on;<br />
tcp_nopush     on;</p>
<p>keepalive_timeout 60;</p>
<p>tcp_nodelay on;</p>
<p>fastcgi_connect_timeout 300;<br />
fastcgi_send_timeout 300;<br />
fastcgi_read_timeout 300;<br />
fastcgi_buffer_size 64k;<br />
fastcgi_buffers 4 64k;<br />
fastcgi_busy_buffers_size 128k;<br />
fastcgi_temp_file_write_size 128k;</p>
<p>fastcgi_intercept_errors on;</p>
<p>gzip on;<br />
gzip_min_length  1k;<br />
gzip_buffers     4 16k;<br />
gzip_http_version 1.0;<br />
gzip_comp_level 2;<br />
gzip_types       text/plain application/x-javascript text/css application/xml;<br />
gzip_vary on;</p>
<p>#limit_zone  crawler  $binary_remote_addr  10m;</p>
<p>server {<br />
listen       80;<br />
server_name  www.example.com  example.com;<br />
root   /opt/www/examplecom;<br />
index  index.html index.htm index.php;</p>
<p>location ~ .*\.(php|php5)?$</p>
<p>{<br />
fastcgi_pass  unix:/tmp/php-cgi.sock;<br />
#fastcgi_pass  127.0.0.1:9000;<br />
fastcgi_index index.php;<br />
include fcgi.conf;<br />
}</p>
<p>location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$<br />
{<br />
expires      30d;<br />
}</p>
<p>location ~ .*\.(js|css)?$<br />
{<br />
expires      1h;<br />
}</p>
<p>}</p>
<p>}</p>
<p>vi /usr/local/webserver/nginx/conf/fcgi.conf ,这里设置fastcgi相关信息,配置如下（示例）：</p>
<p>fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;<br />
fastcgi_param  SERVER_SOFTWARE    nginx;</p>
<p>fastcgi_param  QUERY_STRING       $query_string;<br />
fastcgi_param  REQUEST_METHOD     $request_method;<br />
fastcgi_param  CONTENT_TYPE       $content_type;<br />
fastcgi_param  CONTENT_LENGTH     $content_length;</p>
<p>fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;<br />
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;<br />
fastcgi_param  REQUEST_URI        $request_uri;<br />
fastcgi_param  DOCUMENT_URI       $document_uri;<br />
fastcgi_param  DOCUMENT_ROOT      $document_root;<br />
fastcgi_param  SERVER_PROTOCOL    $server_protocol;</p>
<p>fastcgi_param  REMOTE_ADDR        $remote_addr;<br />
fastcgi_param  REMOTE_PORT        $remote_port;<br />
fastcgi_param  SERVER_ADDR        $server_addr;<br />
fastcgi_param  SERVER_PORT        $server_port;<br />
fastcgi_param  SERVER_NAME        $server_name;</p>
<p># PHP only, required if PHP was built with &#8211;enable-force-cgi-redirect<br />
fastcgi_param  REDIRECT_STATUS    200;</p>
<p>各项配置的具体意义请阅读相关文档：</p>
<p><a title="nginx官方文档" href="http://nginx.org/en/docs/" target="_blank">nginx官方文档</a></p>
<p>&nbsp;</p>
<p>启动nginx<br />
/usr/local/webserver/nginx/sbin/nginx</p>
<p>另外：<br />
nginx重启命令：/usr/local/webserver/nginx/sbin/nginx -s reload<br />
php的重启 /etc/init.d/php-fpm reload</p>
<p>cd /opt/www/examplecom</p>
<p>创建phpinfo页面，查看是否安装成功。到此全部安装结束。</p>
<p>在solaris实际安装nginx的过程中ssl可能会出错，此时指定&#8211;with-openssl=DIR  选项，特别要注意的是此处的DIR是指openssl的安装文件源码所在的目录，而不是openssl安装以后的目录。如果还是有错误直接pkg-get install nginx也是一种选择，这种安装方式版本可能会比较低，但这种方式我认为不会比自己编译安装差，毕竟此时nginx主要起代理作用，另外我也不认为自己编译安装会比solaris官方提供的nginx更优化。</p>
<p>另外nginx+php5.3+ 在linux上的编译安装过程也大同小异，以上过程也可作为参考。</p>
<p>本次安装过程中参考了一下文章：<a href="http://blog.s135.com/nginx_php_v6/" target="_blank">http://blog.s135.com/nginx_php_v6/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.zeevin.com/20111199.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>谷歌免费dns服务</title>
		<link>http://www.zeevin.com/20111178.html</link>
		<comments>http://www.zeevin.com/20111178.html#comments</comments>
		<pubDate>Thu, 10 Nov 2011 14:04:00 +0000</pubDate>
		<dc:creator>zeevin</dc:creator>
				<category><![CDATA[其它相关]]></category>

		<guid isPermaLink="false">http://www.xspider.org/?p=78</guid>
		<description><![CDATA[&#160;&#160;&#160;&#160;&#160;&#160;国内某些地区的运营商会劫持dns，比如山东联通，当用户访问一个不存在的网址，dns查找不到对应的IP，应该返回页面载入出错页面，但是山东联通会重定向到它自己的一个导航页，非常令人恶心，使用谷歌dns可以避免此问题。 目前谷歌提供了两个dns：8.8.8.8 和 8.8.4.4]]></description>
			<content:encoded><![CDATA[<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;国内某些地区的运营商会劫持dns，比如山东联通，当用户访问一个不存在的网址，dns查找不到对应的IP，应该返回页面载入出错页面，但是山东联通会重定向到它自己的一个导航页，非常令人恶心，使用谷歌dns可以避免此问题。<br />
目前谷歌提供了两个dns：8.8.8.8 和 8.8.4.4</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zeevin.com/20111178.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php 3des加密解密，兼容java</title>
		<link>http://www.zeevin.com/20111161.html</link>
		<comments>http://www.zeevin.com/20111161.html#comments</comments>
		<pubDate>Wed, 09 Nov 2011 07:40:23 +0000</pubDate>
		<dc:creator>zeevin</dc:creator>
				<category><![CDATA[PHP/Python/C]]></category>
		<category><![CDATA[3des]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.xspider.org/?p=61</guid>
		<description><![CDATA[首先要明确3des加密的模式，是ecb还是cbc还是其他。 以下是php代码： &#60;?php /** * @author Connor caokang@foxmail.com * @abstract 3des */ &#160; class DES &#123; private $key = 'DE2JCADLNF85E890H887Wa6'; //只有CBC模式下需要iv，其他模式下iv会被忽略 //private $iv = 'B500290096000A007600E3005700C4003800A40018008500'; private $iv = '12345678'; &#160; /** * 加密 */ public function encrypt&#40;$value&#41; &#123; //先确定加密模式，此处以ECB为例 $td = mcrypt_module_open &#40; MCRYPT_3DES,'', MCRYPT_MODE_ECB,''&#41;; //$iv = pack ( 'H16', $this-&#62;iv ); $value = $this-&#62;PaddingPKCS7 [...]]]></description>
			<content:encoded><![CDATA[<p>首先要明确3des加密的模式，是ecb还是cbc还是其他。</p>
<p>以下是php代码：</p>

<div class="wp_code"><div class="pre"><pre class="php" style="font-family:'Times New Roman',Garamond, Times;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
* @author Connor caokang@foxmail.com
* @abstract 3des
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> DES <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'DE2JCADLNF85E890H887Wa6'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//只有CBC模式下需要iv，其他模式下iv会被忽略 </span>
<span style="color: #666666; font-style: italic;">//private $iv = 'B500290096000A007600E3005700C4003800A40018008500';</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$iv</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'12345678'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * 加密
 */</span>
<span style="color: #000000; font-weight: bold;">public</span>  <span style="color: #000000; font-weight: bold;">function</span> encrypt<span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//先确定加密模式，此处以ECB为例</span>
	<span style="color: #000088;">$td</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mcrypt_module_open</span> <span style="color: #009900;">&#40;</span> MCRYPT_3DES<span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> MCRYPT_MODE_ECB<span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//$iv = pack ( 'H16', $this-&gt;iv );</span>
	<span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">PaddingPKCS7</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$value</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//填充</span>
	<span style="color: #666666; font-style: italic;">//$key = pack ( 'H48', $this-&gt;key );</span>
	<span style="color: #990000;">mcrypt_generic_init</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$td</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">iv</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ret</span> <span style="color: #339933;">=</span> <span style="color: #990000;">base64_encode</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">mcrypt_generic</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$td</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">mcrypt_generic_deinit</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$td</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">mcrypt_module_close</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$td</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$ret</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
* 解密
*/</span>
<span style="color: #000000; font-weight: bold;">public</span>  <span style="color: #000000; font-weight: bold;">function</span> decrypt<span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$td</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mcrypt_module_open</span> <span style="color: #009900;">&#40;</span> MCRYPT_3DES<span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> MCRYPT_MODE_ECB<span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//$iv = pack ( 'H16', $this-&gt;iv );</span>
	<span style="color: #666666; font-style: italic;">//$key = pack ( 'H48', $this-&gt;key );</span>
	<span style="color: #990000;">mcrypt_generic_init</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$td</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">key</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">iv</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ret</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">mdecrypt_generic</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$td</span><span style="color: #339933;">,</span> <span style="color: #990000;">base64_decode</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$value</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ret</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">UnPaddingPKCS7</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$ret</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">mcrypt_generic_deinit</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$td</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">mcrypt_module_close</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$td</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$ret</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span>  <span style="color: #000000; font-weight: bold;">function</span> PaddingPKCS7<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$padlen</span> <span style="color: #339933;">=</span>  <span style="color: #cc66cc;">8</span> <span style="color: #339933;">-</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$data</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">8</span> <span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$padlen</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #000088;">$data</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$padlen</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$data</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span>  <span style="color: #000000; font-weight: bold;">function</span> UnPaddingPKCS7<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$padlen</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ord</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$data</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$padlen</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">8</span> <span style="color: #009900;">&#41;</span><span style="color: #b1b100;">return</span> <span style="color: #000088;">$data</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$padlen</span><span style="color: #339933;">-</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">strlen</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$data</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">ord</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">substr</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #000088;">$i</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$padlen</span><span style="color: #009900;">&#41;</span><span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">return</span> <span style="color: #990000;">substr</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$padlen</span><span style="color: #339933;">-</span><span style="color: #990000;">strlen</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$data</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$d</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DES<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'原文：'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'10$35521913397$2011-10-271'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;br/&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'密文：'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$d</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">encrypt</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$str</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;br/&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'解密：'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$d</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">decrypt</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;br/&gt;'</span><span style="color: #339933;">;</span></pre></div></div>

<p>一下是对应的java样例：</p>

<div class="wp_code"><div class="pre"><pre class="java" style="font-family:'Times New Roman',Garamond, Times;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">name</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.crypto.spec.SecretKeySpec</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.crypto.Cipher</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.crypto.SecretKey</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.security.MessageDigest</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">sun.misc.BASE64Encoder</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">sun.misc.BASE64Decoder</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.text.SimpleDateFormat</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.URLEncoder</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.URLDecoder</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.UnsupportedEncodingException</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SecurityUtil  <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> Algorithm <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;DESede&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//定义 加密算法,可用 DES,DESede,Blowfish</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> ENCODODING <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	* SHA1 加密,此处返回  Base64( SHA1( str ))
	* @param sourceString String
	* @return String
	*/</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> toSHA1<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> targetString <span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> encryptSHA1<span style="color: #009900;">&#40;</span> targetString <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	* Base64加密
	* @param targetString String
	* @return String
	*/</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> toBase64<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> targetString<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> enCodesBase64<span style="color: #009900;">&#40;</span> targetString.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	* Base64解密,返回 utf-8 String
	* @param targetString String
	* @return String
	*/</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> fromBase64<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> targetString<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> tmp <span style="color: #339933;">=</span> deCodebase64<span style="color: #009900;">&#40;</span> targetString <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> tmp <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#40;</span>tmp,ENCODODING<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> targetString<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	* ThreeDES加密,此处 toThreeDES = Base64( 3DES( str ))
	* @param sKey String
	* @param targetString String
	* @return String
	*/</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> toThreeDES<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> sKey,<span style="color: #003399;">String</span> targetString<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span>  encryptMode<span style="color: #009900;">&#40;</span> sKey.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,targetString<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	* ThreeDES解密,此处 fromTreeDES = 3DES( Base64( str ))
	* @param sKey String
	* @param targetString String
	* @return String
	*/</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> fromThreeDES<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> sKey,<span style="color: #003399;">String</span> targetString<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span>  decryptMode<span style="color: #009900;">&#40;</span> sKey.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,targetString<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> encryptMode<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> keybyte, <span style="color: #003399;">String</span> inputStr<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span>  <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
		SecretKey deskey <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SecretKeySpec<span style="color: #009900;">&#40;</span>keybyte, Algorithm<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		Cipher c1 <span style="color: #339933;">=</span> Cipher.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span>Algorithm<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		c1.<span style="color: #006633;">init</span><span style="color: #009900;">&#40;</span>Cipher.<span style="color: #006633;">ENCRYPT_MODE</span>, deskey<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> enCodesBase64<span style="color: #009900;">&#40;</span>c1.<span style="color: #006633;">doFinal</span><span style="color: #009900;">&#40;</span>inputStr.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> decryptMode<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> keybyte, <span style="color: #003399;">String</span> inputStr<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span>  <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> input <span style="color: #339933;">=</span> deCodebase64<span style="color: #009900;">&#40;</span>inputStr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		SecretKey deskey <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SecretKeySpec<span style="color: #009900;">&#40;</span>keybyte, Algorithm<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		Cipher c1 <span style="color: #339933;">=</span> Cipher.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span>Algorithm<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		c1.<span style="color: #006633;">init</span><span style="color: #009900;">&#40;</span>Cipher.<span style="color: #006633;">DECRYPT_MODE</span>, deskey<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#40;</span>c1.<span style="color: #006633;">doFinal</span><span style="color: #009900;">&#40;</span>input<span style="color: #009900;">&#41;</span>, ENCODODING<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> encryptSHA1<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> inputStr<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">MessageDigest</span> md <span style="color: #339933;">=</span> <span style="color: #003399;">MessageDigest</span>.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SHA1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		md.<span style="color: #006633;">update</span><span style="color: #009900;">&#40;</span>inputStr.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> sha <span style="color: #339933;">=</span> md.<span style="color: #006633;">digest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">String</span> shaStr <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> sha.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">String</span> hexStr <span style="color: #339933;">=</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">toHexString</span><span style="color: #009900;">&#40;</span>sha<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;</span> 0xFF<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>hexStr.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
			hexStr <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;0&quot;</span> <span style="color: #339933;">+</span> hexStr<span style="color: #339933;">;</span>
			hexStr <span style="color: #339933;">=</span> hexStr.<span style="color: #006633;">toUpperCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			shaStr <span style="color: #339933;">=</span> shaStr <span style="color: #339933;">+</span> hexStr<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #666666; font-style: italic;">//String str=new String(sha).toUpperCase();</span>
		<span style="color: #000000; font-weight: bold;">return</span> enCodesBase64<span style="color: #009900;">&#40;</span>shaStr.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> enCodesBase64<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> input<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
		BASE64Encoder encoder<span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> BASE64Encoder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> encoder.<span style="color: #006633;">encode</span><span style="color: #009900;">&#40;</span>input<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> deCodebase64<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> inputStr<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
		BASE64Decoder decoder <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> BASE64Decoder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> decoder.<span style="color: #006633;">decodeBuffer</span><span style="color: #009900;">&#40;</span>inputStr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//return Base64.decode(inputStr);</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.zeevin.com/20111161.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

