Simple install of memcached on Ubuntu
Posted on January 22, 2010
Memcached is a free, high performance distributed memory object caching system. In English, it can make your single server PHP applications faster or for a little more technical users you can write cache and share cache objects over a web server farm or cluster. Great, eh.
No seriously, it can really make your PHP faster.Here is how to install it really simply on Ubuntu for use with PHP.
apt-get install memcached php5-memcacheSimple as that!
Lets check it's running
itsupport@intranet4:~$ ps uxa | grep memcachenobody 8108 0.0 0.8 19104 17664 ? S Jan20 0:00 /usr/bin/memcached -m 64 -p 11211 -u nobody -l 127.0.0.1By default its running on localhost only and on the default port of 11211. You can change these if you need network access or whatever in /etc/memcached.conf. But we'll leave it as default for now.
Now, how hard was that?
PHP lists a simple example file to test PHP and memcached interoperatability.
<?php
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");
$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>\n";
$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = 123;
$memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");
echo "Store data in the cache (data will expire in 10 seconds)<br/>\n";
$get_result = $memcache->get('key');
echo "Data from the cache:<br/>\n";
var_dump($get_result);
?>Related posts:
- Installing memcached on CentOS (cPanel)
Welcome to hell. No really, compared to installing memcached on Ubuntu, CentOSs really sucks. CentOS... - Ridiculously simple NTLM Authentication for Apache (Ubuntu)
We all know Ubuntu makes things amazingly simple. This is the best I've found so... - Really freakin’ simple mysql virtual hosting pure-ftpd
This article will guide you through installing pure-ftpd configured for virtual hosts using mysql as... - mod_geoip Revisted including stopping spam in phpBB 2
I've recently moved a client's forum onto a new cPanel server, previously it was on... - Install Imagemagick / Imagick for PHP on Ubuntu
No problem if you want to install imagemagick on your server, Ubuntu makes this very...