kieranbarnes Independent PHP, WordPress & CubeCart Programmer

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.

  1. apt-get install memcached php5-memcache

Simple as that!

Lets check it's running

  1. itsupport@intranet4:~$ ps uxa | grep memcache
  1. 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.

  1. <?php
  2.  
  3. $memcache = new Memcache;
  4. $memcache->connect('localhost', 11211) or die ("Could not connect");
  5.  
  6. $version = $memcache->getVersion();
  7. echo "Server's version: ".$version."<br/>\n";
  8.  
  9. $tmp_object = new stdClass;
  10. $tmp_object->str_attr = 'test';
  11. $tmp_object->int_attr = 123;
  12.  
  13. $memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");
  14. echo "Store data in the cache (data will expire in 10 seconds)<br/>\n";
  15.  
  16. $get_result = $memcache->get('key');
  17. echo "Data from the cache:<br/>\n";
  18.  
  19. var_dump($get_result);
  20.  
  21. ?>

Related posts

  1. Installing memcached on CentOS/cPanel
    memcached a (distributed) memory object caching system vital if your running a HA Linux* setup...
  2. Installing memcached on CentOS (cPanel)
    Welcome to hell. No really, compared to installing memcached on Ubuntu, CentOSs really sucks. CentOS...
  3. Ridiculously simple NTLM Authentication for Apache (Ubuntu)
    We all know Ubuntu makes things amazingly simple. This is the best I've found so...
  4. [Snippet] Stupid Simple cPanel Install
    Open a clean server, Go have your lunch. Maybe lunch +VAT depending on the speed...
  5. Installing nginx & PHP-FPM securely on CentOS
    I won't go into the reasons why you should install nginx, if you're here, you've...

Posted by Kieran


Tagged as: Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.