<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[memcache - All your code are belong to us]]></title><description><![CDATA[Thoughts, stories and ideas on code and technology in general.<br>Blog title inspired by <a href="https://en.wikipedia.org/wiki/All_your_base_are_belong_to_us" target="_blank">this meme</a>]]></description><link>https://allurcode.com/</link><image><url>https://allurcode.com/favicon.png</url><title>memcache - All your code are belong to us</title><link>https://allurcode.com/</link></image><generator>Ghost 4.48</generator><lastBuildDate>Thu, 04 Jun 2026 13:05:03 GMT</lastBuildDate><atom:link href="https://allurcode.com/tag/memcache/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[PHP session handling with memcache]]></title><description><![CDATA[<!--kg-card-begin: markdown--><p>In last two posts I described how to install <a href="https://allurcode.com/how-to-install-memcached-on-centos/">memcached</a> daemon and <a href="https://allurcode.com/how-to-run-memcache-in-php/">memcache</a> extension for PHP. Today I&apos;ll show you how to configure your PHP to use memcache to handle sessions.</p>
<p>One thing I should mention is that when installing memcache you should answer <strong>yes</strong> when asked</p>
<pre><code>1.</code></pre>]]></description><link>https://allurcode.com/php-session-handling-with-memcache/</link><guid isPermaLink="false">5b7b0aa2b52b43084c9ea11b</guid><category><![CDATA[memcache]]></category><category><![CDATA[PHP]]></category><category><![CDATA[session]]></category><dc:creator><![CDATA[Wojtek]]></dc:creator><pubDate>Tue, 16 Mar 2010 11:53:41 GMT</pubDate><content:encoded><![CDATA[<!--kg-card-begin: markdown--><p>In last two posts I described how to install <a href="https://allurcode.com/how-to-install-memcached-on-centos/">memcached</a> daemon and <a href="https://allurcode.com/how-to-run-memcache-in-php/">memcache</a> extension for PHP. Today I&apos;ll show you how to configure your PHP to use memcache to handle sessions.</p>
<p>One thing I should mention is that when installing memcache you should answer <strong>yes</strong> when asked</p>
<pre><code>1. Enable memcache session handler support? : yes
</code></pre>
<p>First of all, lets start two memcached processes just in case one crashes, we&#x2019;ll have a second one ready right away.</p>
<pre><code class="language-bash">memcached -u root -d -m 512 -l 127.0.0.1 -p 11211
memcached -u root -d -m 512 -l 127.0.0.1 -p 11212
</code></pre>
<p>Worth mentioning is that when one memcached process crashes session information will not be transferred to another. New session will be started.</p>
<p>Next edit your <code>php.ini</code> file. Comment out the line with your current session handler setting</p>
<pre><code class="language-bash">; session.save_handler = files
</code></pre>
<p>and add two new lines</p>
<pre><code class="language-bash">session.save_handler = memcache
session.save_path = &quot;tcp://localhost:11211, tcp://localhost:11212&quot;
</code></pre>
<p>If for any reason you don&#x2019;t want to edit <code>php.ini</code> file you can set those options directly in your PHP script.</p>
<pre><code class="language-bash">ini_set(&apos;session.save_handler&apos;, &apos;memcache&apos;);
ini_set(&apos;session.save_path&apos;, &apos;tcp://localhost:11211, tcp://localhost:11212&apos;);
</code></pre>
<p>Restart your web server</p>
<pre><code class="language-bash">service httpd restart
</code></pre>
<p>For full list of runtime configuration options go <a href="https://www.php.net/manual/en/memcache.ini.php">here</a>.</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[How to run memcache in PHP]]></title><description><![CDATA[<!--kg-card-begin: markdown--><p>After installing <a href="https://allurcode.com/how-to-install-memcached-on-centos/"><strong>memcached</strong></a> daemon, we have to install memcache PHP extension.</p>
<pre><code class="language-bash">yum install php-pecl-memcache
</code></pre>
<p>or</p>
<pre><code class="language-bash">apt-get install php5-memcache
</code></pre>
<p>If above is not an option try below method.</p>
<pre><code class="language-bash">pecl install memcache
</code></pre>
<p>After successful installation add <code>memcache.so</code> extension to your <code>php.ini</code> file.</p>
<pre><code class="language-bash">vim /etc/php.ini
</code></pre>
<p>Add this line:</p>
<pre><code>extension=</code></pre>]]></description><link>https://allurcode.com/how-to-run-memcache-in-php/</link><guid isPermaLink="false">5b7b0aa2b52b43084c9ea11a</guid><category><![CDATA[CentOS]]></category><category><![CDATA[Linux]]></category><category><![CDATA[memcache]]></category><category><![CDATA[PHP]]></category><dc:creator><![CDATA[Wojtek]]></dc:creator><pubDate>Sat, 13 Mar 2010 01:51:11 GMT</pubDate><content:encoded><![CDATA[<!--kg-card-begin: markdown--><p>After installing <a href="https://allurcode.com/how-to-install-memcached-on-centos/"><strong>memcached</strong></a> daemon, we have to install memcache PHP extension.</p>
<pre><code class="language-bash">yum install php-pecl-memcache
</code></pre>
<p>or</p>
<pre><code class="language-bash">apt-get install php5-memcache
</code></pre>
<p>If above is not an option try below method.</p>
<pre><code class="language-bash">pecl install memcache
</code></pre>
<p>After successful installation add <code>memcache.so</code> extension to your <code>php.ini</code> file.</p>
<pre><code class="language-bash">vim /etc/php.ini
</code></pre>
<p>Add this line:</p>
<pre><code>extension=memcache.so
</code></pre>
<p>Restart web server</p>
<pre><code class="language-bash">service httpd restart
</code></pre>
<p>Test out our installation.</p>
<pre><code class="language-bash">&lt;?php
$memcache = new Memcache;
$memcache-&gt;connect(&apos;localhost&apos;, 11211) or die (&apos;Can\&apos;t connect!&apos;);
$version = $memcache-&gt;getVersion();
echo &apos;Server version: &apos;.$version;
</code></pre>
<p>You should see your server&#x2019;s version number. If you see a blank page make sure that <a href="https://allurcode.com/how-to-install-memcached-on-centos/">memcached</a> daemon is working. If you&#x2019;re getting &quot;Can&#x2019;t connect!&quot; message despite running daemon try changing &apos;localhost&apos; to &apos;127.0.0.1&apos;.</p>
<!--kg-card-end: markdown-->]]></content:encoded></item></channel></rss>