kieranbarnes do you know where your towel is?

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-memcache

Simple as that!

Lets check it's running

itsupport@intranet4:~$ ps uxa | grep memcache
nobody    8108  0.0  0.8  19104 17664 ?        S    Jan20   0:00 /usr/bin/memcached -m 64 -p 11211 -u nobody -l 127.0.0.1

By 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);
 
?>
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

Related posts:

  1. Installing memcached on CentOS (cPanel)
    Welcome to hell. No really, compared to installing memcached on Ubuntu, CentOSs really sucks. CentOS...
  2. Ridiculously simple NTLM Authentication for Apache (Ubuntu)
    We all know Ubuntu makes things amazingly simple. This is the best I've found so...
  3. [Snippet] Stupid Simple cPanel Install
    Open a clean server, Go have your lunch. Maybe lunch +VAT depending on the speed...
  4. Really freakin’ simple mysql virtual hosting pure-ftpd
    This article will guide you through installing pure-ftpd configured for virtual hosts using mysql as...
  5. cPanel MySQL Tuning
    The default configuration for MySQL provided by cPanel is pretty barren. /etc/my.cnf Thats it. One...

What this article useful to you?



Let me know, buy me a beer!
Alternatively, if you're feeling impecunious, you may like to subscribe to my RSS feed, or see other articles in the Geeky, Linux category.

Filed under: Geeky, Linux Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.