<?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; failed</title>
	<atom:link href="http://www.qingliangcn.com/tag/failed/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>Wed, 11 Aug 2010 15:25:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>PHP中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>

