星期一, 7月 30, 2012

install memcache for php

本想說這東西就yum一下就好了...
沒想到重裝時,還真卡住了,想不起來怎麼裝的
還是乖乖寫筆記吧

  • 架memcache server
    1. 事前準備
      yum install libevent
      yum install libmemcached libmemcached-devel
    2. 裝memcache server
      yum install memcached
    3. Start Memcached server
      memcached -d -m 512 -l 127.0.0.1 -p 11211 -u nobody
      d = daemon, m = memory, u = user, l = IP to listen to, p = port)
  • php存取memcache
    1. 事前準備
      利用pecl安裝,如果沒有的...
      yum install php-pear
    2. 安裝memcache
      pecl install memcache
    3. 設定php.ini
      將extension寫入php.ini
      extension=memcache.so
    4. 設定memcache server位置
      $memcache = new Memcache; 
      $memcache->connect('127.0.0.1', 11211) or die ("Could not connect"); //connect to memcached server   
      $mydata = "i want to cache this line"; //your cacheble data   
      $memcache->set('key', $mydata, false, 100); //add it to memcached server   $get_result = $memcache->get('key'); //retrieve your data   
      var_dump($get_result); //show it
就這麼簡單...

Reference

10 baby steps to install Memcached Server and access it with PHP


沒有留言: