memcacheをsymfonyから利用してみました。
まずはyumを利用してmemcachedをインストールし、起動。
# yum install memcached
# chkconfig --level 345 memcached on
# /etc/init.d/memcached start
phpからmemcacheにアクセスする環境をつくる。
# pecl install memcache
php.iniに下記を追加し、apacheを再起動
extension=/usr/local/lib/php/extensions/no-debug-non-zts-20060613/memcache.so
今回はsymfonyから簡単にmemcacheを利用できるプラグイン、sfMemcachePluginを利用する。
$ symfony plugin-install http://plugins.symfony-project.com/sfMemcachePlugin
pluginのconfigディレクトリにある、2ファイルをアプリケーションのconfigディレクトリにコピー
$ cp plugins/sfMemcachePlugin/config/config_handlers.yml apps/app_dir/config/
$ cp plugins/sfMemcachePlugin/config/memcache.yml apps/app_dir/config/
memcache.ymlにmemcacheサーバに接続するホストなどの情報を書き換える。
-
all:
-
servers:
-
default:
-
host: localhost
-
port: 11211
-
timeout: 1
-
weight: 1
-
retry_interval: 1
-
status: 1
-
buckets:
-
default:
-
servers: default
-
news:
-
servers: default
これで準備は完了。あとは利用方法はこんな感じ。
-
$namespace = 'sample_namespace';
-
$key = 'key';
-
$fc = new sfMemcacheFunctionCache;
-
$result = '';
-
if ($fc->has($key, $namespace, ''))
-
{
-
$result = $fc->get($key, $namespace, '');
-
}
-
else
-
{
-
$result = 'result!!';
-
$fc->set($key, $namespace, $result);
-
}



Pingback: Windows+PHP+memcached+symfony | 秋元@どす恋リミテッド
Pingback: Absolute Playing!