<?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[session - 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>session - All your code are belong to us</title><link>https://allurcode.com/</link></image><generator>Ghost 4.48</generator><lastBuildDate>Tue, 31 Mar 2026 11:25:10 GMT</lastBuildDate><atom:link href="https://allurcode.com/tag/session/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></channel></rss>