<?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>庆亮的博客-webgame架构 &#187; PHP高级应用</title>
	<atom:link href="http://www.qingliangcn.com/category/php_advanced_application/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.qingliangcn.com</link>
	<description>关注LAMP&#124;PHP源代码分析&#124;web架构&#124;PHP扩展&#124;Erlang&#124;服务端架构</description>
	<lastBuildDate>Thu, 22 Jul 2010 09:19:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>PHP中Exception性能简单测试及结论</title>
		<link>http://www.qingliangcn.com/2009/11/php%e4%b8%adexception%e6%80%a7%e8%83%bd%e7%ae%80%e5%8d%95%e6%b5%8b%e8%af%95%e5%8f%8a%e7%bb%93%e8%ae%ba/</link>
		<comments>http://www.qingliangcn.com/2009/11/php%e4%b8%adexception%e6%80%a7%e8%83%bd%e7%ae%80%e5%8d%95%e6%b5%8b%e8%af%95%e5%8f%8a%e7%bb%93%e8%ae%ba/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 13:08:14 +0000</pubDate>
		<dc:creator>庆亮</dc:creator>
				<category><![CDATA[PHP高级应用]]></category>

		<guid isPermaLink="false">http://www.nd21.com/?p=192</guid>
		<description><![CDATA[关于是否使用exception风格（个人的说法，也就是非正常的返回值都以抛异常的形式返回）来编码，我产生了一些疑问，经过和同事的一些讨论，我决定做些简单的性能测试。 &#60;?php /** &#160;*&#160;Exception&#160;简单的性能测试 &#160;*&#160;@author&#160;Qingliang.Cn&#160;&#160;qing.liang.cn@gmail.com &#160;*&#160;@created&#160;2009-11-18&#160; &#160;*&#160;@lastmodified&#160;2009-11-18 &#160;*/ define(&#8216;T&#8217;,&#160;1000000); function&#160;no_except($a,&#160;$b) { &#160;&#160;&#160;&#160;if&#160;(mt_rand(1,&#160;10)&#160;&#62;&#160;0){ &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return&#160;$a&#160;+&#160;$b; &#160;&#160;&#160;&#160;} } function&#160;except($a,&#160;$b) { &#160;&#160;&#160;&#160;try&#160;{ &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if&#160;(mt_rand(1,&#160;10)&#160;&#62;&#160;5){&#160;//&#160;&#160;0.5的概率抛出异常 &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return&#160;$a&#160;+&#160;$b; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}else{ &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;throw&#160;new&#160;Exception(1); &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;} &#160;&#160;&#160;&#160;}catch&#160;(Exception&#160;$e){ &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return&#160;$e-&#62;getMessage(); &#160;&#160;&#160;&#160;} } echo&#160;&#34;1.&#160;with&#160;no&#160;exception,&#160;time&#160;is:&#34;; $begin&#160;=&#160;microtime(true); for&#160;($i=0;&#160;$i&#60;&#160;T;&#160;$i++) { &#160;&#160;&#160;&#160;no_except(1,&#160;1); } echo&#160;microtime(true)&#160;-&#160;$begin; echo&#160;&#34;\r\n&#34;; echo&#160;&#34;2.&#160;with&#160;exception,&#160;time&#160;is:&#34;; $begin&#160;=&#160;microtime(true); for&#160;($i=0;&#160;$i&#60;&#160;T;&#160;$i++) { &#160;&#160;&#160;&#160;except(1,&#160;1); } echo&#160;microtime(true)&#160;-&#160;$begin; echo&#160;&#34;\r\n&#34;; 结果： 100000&#160;(10W) 1.&#160;with&#160;no&#160;exception,&#160;time&#160;is:3.2554759979248 2.&#160;with&#160;exception,&#160;time&#160;is:4.2815051078796 1000000(100W) 1.&#160;with&#160;no&#160;exception,&#160;time&#160;is:31.89279794693 2.&#160;with&#160;exception,&#160;time&#160;is:39.047714948654 上面的测试结果可以看出消耗的时间是相当稳定的，直接的结果是exception比直接return要慢。&#160; 继续分析 抛出异常的概率为0.5，也就是说：50w次的异常处理导致了11秒的性能损失。每次exception处理的消耗大概是&#160;20&#160;微秒，这个消耗是相当的小的。&#160;因为一般情况下，web请求的时间都是ms级别的。 同时这里还有两点需要注意： 1.&#160;没有使用异常的时候，代码中的逻辑判断分值必然会加多，也是一定的消耗。 [...]]]></description>
			<content:encoded><![CDATA[<div class="Section0" style="layout-grid:  15.6pt none">
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">关于是否使用<font face="Courier New">exception</font><font face="宋体">风格（个人的说法，也就是非正常的返回值都以抛异常的形式返回）来编码，我产生了一些疑问，经过和同事的一些讨论，我决定做些简单的性能测试。</font></span><span style="font-family: '宋体'; color: rgb(255,0,0); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(255,0,0); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(255,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&lt;?php</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(128,128,128); font-size: 10.5pt; mso-spacerun: 'yes'">/**</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(128,128,128); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;*&nbsp;Exception&nbsp;简单的性能测试</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(128,128,128); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;*&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128,128,128); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">@author</span><span style="font-family: 'Courier New'; color: rgb(128,128,128); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;Qingliang.Cn&nbsp;&nbsp;qing.liang.cn@gmail.com</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(128,128,128); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;*&nbsp;@created&nbsp;2009-11-18&nbsp;</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(128,128,128); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;*&nbsp;@lastmodified&nbsp;2009-11-18</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(128,128,128); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;*/</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">define(</span><span style="font-family: 'Courier New'; color: rgb(0,130,0); font-size: 10.5pt; mso-spacerun: 'yes'">&#8216;T&#8217;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(255,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">1000000</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">);</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">function&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">no_except(</span><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">$a</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">$b</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">{</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">if&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">(mt_rand(</span><span style="font-family: '宋体'; color: rgb(255,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">1</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(255,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">10</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;&gt;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(255,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">0</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">){</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">return&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">$a&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">+&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">$b</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">;</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;}</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">function&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">except(</span><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">$a</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">$b</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">{</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">try&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">{</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">if&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">(mt_rand(</span><span style="font-family: '宋体'; color: rgb(255,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">1</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(255,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">10</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;&gt;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(255,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">5</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">){</span><span style="font-family: '宋体'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;//&nbsp;&nbsp;0.5<font face="宋体">的概率抛出异常</font></span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">return&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">$a&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">+&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">$b</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">;</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">else</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">{</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">throw&nbsp;new&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">Exception(</span><span style="font-family: 'Courier New'; color: rgb(255,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">1</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">);</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;}</span><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">catch&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">(Exception&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">$e</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">){</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">return&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">$e</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">-&gt;getMessage();</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;}</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">echo&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,130,0); font-size: 10.5pt; mso-spacerun: 'yes'">&quot;1.&nbsp;with&nbsp;no&nbsp;exception,&nbsp;time&nbsp;is:&quot;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">;</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">$begin&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">=&nbsp;microtime(</span><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">true</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">);</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">for&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">(</span><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">$i</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">=</span><span style="font-family: 'Courier New'; color: rgb(255,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">0</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">$i</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&lt;&nbsp;T;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">$i</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">++)</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">{</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;no_except(</span><span style="font-family: 'Courier New'; color: rgb(255,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">1</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(255,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">1</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">);</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">echo&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">microtime(</span><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">true</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;-&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">$begin</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">;</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">echo&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,130,0); font-size: 10.5pt; mso-spacerun: 'yes'">&quot;\r\n&quot;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">;</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">echo&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,130,0); font-size: 10.5pt; mso-spacerun: 'yes'">&quot;2.&nbsp;with&nbsp;exception,&nbsp;time&nbsp;is:&quot;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">;</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">$begin&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">=&nbsp;microtime(</span><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">true</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">);</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">for&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">(</span><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">$i</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">=</span><span style="font-family: 'Courier New'; color: rgb(255,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">0</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">$i</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&lt;&nbsp;T;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">$i</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">++)</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">{</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;except(</span><span style="font-family: 'Courier New'; color: rgb(255,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">1</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(255,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">1</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">);</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">echo&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">microtime(</span><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">true</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;-&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">$begin</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">;</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">echo&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,130,0); font-size: 10.5pt; mso-spacerun: 'yes'">&quot;\r\n&quot;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">;</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'">结果：</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'">100000&nbsp;(10W)</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '&Euml;&Icirc;&Igrave;&aring;'; color: rgb(0,0,0); font-size: 9pt; mso-spacerun: 'yes'">1.&nbsp;with&nbsp;no&nbsp;exception,&nbsp;time&nbsp;is:3.2554759979248</span><span style="font-family: '&Euml;&Icirc;&Igrave;&aring;'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '&Euml;&Icirc;&Igrave;&aring;'; color: rgb(0,0,0); font-size: 9pt; mso-spacerun: 'yes'">2.&nbsp;with&nbsp;exception,&nbsp;time&nbsp;is:4.2815051078796</span><span style="font-family: '&Euml;&Icirc;&Igrave;&aring;'; color: rgb(0,0,0); font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '&Euml;&Icirc;&Igrave;&aring;'; color: rgb(0,0,0); font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'">1000000(100W)</span><span style="font-family: 'Courier New'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '&Euml;&Icirc;&Igrave;&aring;'; color: rgb(0,0,0); font-size: 9pt; mso-spacerun: 'yes'">1.&nbsp;with&nbsp;no&nbsp;exception,&nbsp;time&nbsp;is:31.89279794693</span><span style="font-family: '&Euml;&Icirc;&Igrave;&aring;'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '&Euml;&Icirc;&Igrave;&aring;'; color: rgb(0,0,0); font-size: 9pt; mso-spacerun: 'yes'">2.&nbsp;with&nbsp;exception,&nbsp;time&nbsp;is:39.047714948654</span><span style="font-family: '&Euml;&Icirc;&Igrave;&aring;'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(128,128,128); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(128,128,128); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">上面的测试结果可以看出消耗的时间是相当稳定的，直接的结果是<font face="Courier New">exception</font><font face="宋体">比直接</font><font face="Courier New">return</font><font face="宋体">要慢。&nbsp;</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">继续分析</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">抛出异常的概率为<font face="Courier New">0.5</font><font face="宋体">，也就是说：</font></span><span style="font-family: '宋体'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">50w<font face="宋体">次的异常处理导致了</font><font face="Courier New">11</font><font face="宋体">秒的性能损失。每次</font><font face="Courier New">exception</font><font face="宋体">处理的消耗大概是&nbsp;</font><font face="Courier New">20&nbsp;</font><font face="宋体">微秒，</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">这个消耗是相当的小的。&nbsp;因为一般情况下，<font face="Courier New">web</font><font face="宋体">请求的时间都是</font><font face="Courier New">ms</font><font face="宋体">级别的。</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">同时这里还有两点需要注意：</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">1.&nbsp;</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">没有使用异常的时候，代码中的逻辑判断分值必然会加多，也是一定的消耗。</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">2.&nbsp;</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">多数的程序<font face="Courier New">exception</font><font face="宋体">命中率不会如上面代码中那么高（</font><font face="Courier New">50%</font><font face="宋体">）。</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="text-align: justify; margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">所以在<font face="Courier New">PHP</font><font face="宋体">中应用</font><font face="Courier New">exception</font><font face="宋体">是不需要考虑性能问题的。</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">如有不同的观点，欢迎拍砖和讨论。&nbsp;<font face="Courier New">email:&nbsp;qing.liang.cn&nbsp;at&nbsp;gmail.com</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="text-align: justify; margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
</div>
<p><!--EndFragment--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.qingliangcn.com/2009/11/php%e4%b8%adexception%e6%80%a7%e8%83%bd%e7%ae%80%e5%8d%95%e6%b5%8b%e8%af%95%e5%8f%8a%e7%bb%93%e8%ae%ba/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP中memcache扩展set失败的解决</title>
		<link>http://www.qingliangcn.com/2009/07/php%e4%b8%admemcache%e6%89%a9%e5%b1%95set%e5%a4%b1%e8%b4%a5%e7%9a%84%e8%a7%a3%e5%86%b3/</link>
		<comments>http://www.qingliangcn.com/2009/07/php%e4%b8%admemcache%e6%89%a9%e5%b1%95set%e5%a4%b1%e8%b4%a5%e7%9a%84%e8%a7%a3%e5%86%b3/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 09:45:05 +0000</pubDate>
		<dc:creator>庆亮</dc:creator>
				<category><![CDATA[PHP高级应用]]></category>
		<category><![CDATA[failed]]></category>
		<category><![CDATA[memcache]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[失败]]></category>

		<guid isPermaLink="false">http://www.nd21.com/?p=78</guid>
		<description><![CDATA[在代码中遇到了memcache set方法失败的问题，无任何错误提示，PHP的memcache扩展本身也没有debug或者error提示。同样的代码，将本地的环境跟服务器的环境对比了一下（在服务器端一直没有遇到这个问题），发现原来是我所使用的php memcache扩展版本较低导致的。PECL有个bug报告http://pecl.php.net/bugs/bug.php?id=9486 ，也是提到这个问题了，在新的版本中已经解决了（2.1.1）。 使用php的memcache扩展时，如果给set/get方法传递一个空值（NULL），则会导致memcached服务端主动关闭连接，见如下的代码示范： &#160; $mem&#160;=&#160;new&#160;Memcache(); $mem-&#62;connect(&#8217;192.168.64.12&#8242;,&#160;&#8217;11211&#8242;); $mem-&#62;set(&#8216;aaa&#8217;,&#160;array(&#8216;aaa&#8217;));&#160;//成功 $mem-&#62;set($aaaa,&#160;&#8216;aaaa&#8217;);&#160;//失败，并导致到memcached服务器的连接丢失，所以之后的方法都失败了（返回false） $mem-&#62;set(&#8216;bbb&#8217;,&#160;array(&#8216;bbb&#8217;));//失败 $mem-&#62;get(&#8216;aaa&#8217;);//失败 没有测试memcached扩展是否有过这样的bug。 顺便提一下在PHP中memcached和memcache是两个不同的扩展，区别是memcached基于libmemcached库封装的API接口。见PHP手册 This extension uses libmemcached library to provide API for communicating with memcached servers. It also provides a session handler (memcached). 而通常所说的memcached就是指memcached服务器端。 另外如果key过长（250以上），value过大（1M以上）或者过期时间过长（大于2592000）都会导致set失败。]]></description>
			<content:encoded><![CDATA[<p>在代码中遇到了memcache set方法失败的问题，无任何错误提示，PHP的memcache扩展本身也没有debug或者error提示。同样的代码，将本地的环境跟服务器的环境对比了一下（在服务器端一直没有遇到这个问题），发现原来是我所使用的php memcache扩展版本较低导致的。PECL有个bug报告http://pecl.php.net/bugs/bug.php?id=9486 ，也是提到这个问题了，在新的版本中已经解决了（2.1.1）。</p>
<p>使用php的memcache扩展时，如果给set/get方法传递一个空值（NULL），则会导致memcached服务端主动关闭连接，见如下的代码示范：<br />
&nbsp;</p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10pt; mso-spacerun: 'yes'">$mem&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">=&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10pt; mso-spacerun: 'yes'">new&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">Memcache();</span><span style="font-family: 'Courier New'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10pt; mso-spacerun: 'yes'">$mem</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">-&gt;connect(</span><span style="font-family: 'Courier New'; color: rgb(0,130,0); font-size: 10pt; mso-spacerun: 'yes'">&#8217;192.168.64.12&#8242;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,130,0); font-size: 10pt; mso-spacerun: 'yes'">&#8217;11211&#8242;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">);</span><span style="font-family: 'Courier New'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10pt; mso-spacerun: 'yes'">$mem</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">-&gt;set(</span><span style="font-family: 'Courier New'; color: rgb(0,130,0); font-size: 10pt; mso-spacerun: 'yes'">&#8216;aaa&#8217;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10pt; mso-spacerun: 'yes'">array</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">(</span><span style="font-family: 'Courier New'; color: rgb(0,130,0); font-size: 10pt; mso-spacerun: 'yes'">&#8216;aaa&#8217;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">));&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128,128,128); font-size: 10pt; mso-spacerun: 'yes'">//成功</span><span style="font-family: 'Courier New'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10pt; text-decoration: underline; mso-spacerun: 'yes'">$mem</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10pt; text-decoration: underline; mso-spacerun: 'yes'">-&gt;set(</span><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10pt; text-decoration: underline; mso-spacerun: 'yes'">$aaaa</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10pt; text-decoration: underline; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,130,0); font-size: 10pt; text-decoration: underline; mso-spacerun: 'yes'">&#8216;aaaa&#8217;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10pt; text-decoration: underline; mso-spacerun: 'yes'">);&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128,128,128); font-size: 10pt; text-decoration: underline; mso-spacerun: 'yes'">//失败，并导致到memcached服务器的连接丢失，所以之后的方法都失败了（返回false）</span><span style="font-family: 'Courier New'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10pt; mso-spacerun: 'yes'">$mem</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">-&gt;set(</span><span style="font-family: 'Courier New'; color: rgb(0,130,0); font-size: 10pt; mso-spacerun: 'yes'">&#8216;bbb&#8217;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0,0,255); font-size: 10pt; mso-spacerun: 'yes'">array</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">(</span><span style="font-family: 'Courier New'; color: rgb(0,130,0); font-size: 10pt; mso-spacerun: 'yes'">&#8216;bbb&#8217;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">));</span><span style="font-family: 'Courier New'; color: rgb(128,128,128); font-size: 10pt; mso-spacerun: 'yes'">//失败</span><span style="font-family: 'Courier New'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Courier New'; color: rgb(102,0,0); font-size: 10pt; mso-spacerun: 'yes'">$mem</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">-&gt;get(</span><span style="font-family: 'Courier New'; color: rgb(0,130,0); font-size: 10pt; mso-spacerun: 'yes'">&#8216;aaa&#8217;</span><span style="font-family: 'Courier New'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">);</span><span style="font-family: 'Courier New'; color: rgb(128,128,128); font-size: 10pt; mso-spacerun: 'yes'">//失败</span><!--EndFragment--></p>
<p>没有测试memcached扩展是否有过这样的bug。<br />
顺便提一下在PHP中memcached和memcache是两个不同的扩展，区别是memcached基于libmemcached库封装的API接口。见PHP手册<br />
This extension uses libmemcached library to provide API for communicating with memcached servers. It also provides a session handler (memcached).</p>
<p>而通常所说的memcached就是指memcached服务器端。</p>
<p>另外如果key过长（250以上），value过大（1M以上）或者过期时间过长（大于2592000）都会导致set失败。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.qingliangcn.com/2009/07/php%e4%b8%admemcache%e6%89%a9%e5%b1%95set%e5%a4%b1%e8%b4%a5%e7%9a%84%e8%a7%a3%e5%86%b3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

