<?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>PHP 4u Web developer - 代码的简化 &#187; memcache</title>
	<atom:link href="http://php4u.co.uk/tag/memcache/feed/" rel="self" type="application/rss+xml" />
	<link>http://php4u.co.uk</link>
	<description>PHP related blog, freelancer to hire!</description>
	<lastBuildDate>Fri, 27 Aug 2010 12:09:42 +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>sfMemcachePlugin limitations</title>
		<link>http://php4u.co.uk/2009/03/sfmemcacheplugin-limitations/</link>
		<comments>http://php4u.co.uk/2009/03/sfmemcacheplugin-limitations/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 09:57:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Symfony]]></category>
		<category><![CDATA[memcache]]></category>
		<category><![CDATA[memory limits]]></category>

		<guid isPermaLink="false">http://php4u.co.uk/?p=36</guid>
		<description><![CDATA[I&#8217;m using quite hapilly sfMemcachePlugin, but recently i needed to store object which was around 2Mb, and problems started. I&#8217;ve spend couple minutes trying to figure out why app is not working, finally i Found that memcache doesn&#8217;t store stuff more than 1Mb. To solve that, I&#8217;ve decided to compress data and then store it, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m using quite hapilly <a title="sfMemcachePlugin" href="http://www.symfony-project.org/plugins/sfMemcachePlugin?format=txt" target="_blank">sfMemcachePlugin</a>, but recently i needed to store object which was around <strong>2Mb</strong>, and problems started. I&#8217;ve spend couple minutes trying to figure out why app is not working, finally i Found that memcache doesn&#8217;t store stuff more than <strong>1Mb</strong>.  To solve that, I&#8217;ve decided to compress data and then store it, but if data is still over limit i&#8217;m switching to sessions anyway.</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p36code2'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p362"><td class="code" id="p36code2"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/extension_loaded"><span style="color: #990000;">extension_loaded</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'zlib'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// there is 1024Kb limitation on memcache, so we need to compress</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_storing_method <span style="color: #339933;">=</span> <span style="color: #0000ff;">'sessions'</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;">function</span> someFunctionToStoreData<span style="color: #009900;">&#40;</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: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_storing_method<span style="color: #339933;">==</span><span style="color: #0000ff;">'sessions'</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			sfContext<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'variableId'</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_varToStore<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// compress</span>
                        <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/gzcompress"><span style="color: #990000;">gzcompress</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/serialize"><span style="color: #990000;">serialize</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_varToStore<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">// compute data size</span>
                        <span style="color: #000088;">$data_size</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/strlen"><span style="color: #990000;">strlen</span></a><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;">1024</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">1024</span><span style="color: #339933;">;</span>
                        <span style="color: #666666; font-style: italic;">// log it in symfony</span>
			sfContext<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLogger</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Data size for memcache to store is '</span><span style="color: #339933;">.</span><span style="color: #000088;">$data_size</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; Mb&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #666666; font-style: italic;">// check data size - 0.9Mb - just in case to not go over 1Mb</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data_size</span><span style="color: #339933;">&gt;</span><span style="color:#800080;">0.9</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_storing_method<span style="color: #339933;">=</span><span style="color: #0000ff;">'sessions'</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">someFunctionToStoreData</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			sfMemcacheFunctionCache<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'variableId'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'OurNameSpace'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		sfContext<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLogger</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Setting search ordering variable for country '</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_locationId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://php4u.co.uk/2009/03/sfmemcacheplugin-limitations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.411 seconds -->
