Archive for the 'php' Category

CentOS:memcachedをインストール

CentOs5.2のリポジトリにmemcachedは無いのでリポジトリを追加する。

cd /usr/local/src
wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rpm -Uhv rpmforge-release-0.3.6-1.el5.rf.i386.rpm

mencachedを入れるのに必要なモジュールをインストールする。
たぶんこのあたりを入れておけばおっけーなはず。

yum install gcc
yum install memcached
yum install zlib-devel
yum install php-pecl-memcache

memcachedの設定は/etc/sysconfig/memcachedを編集する。
動かすだけならデフォルトのままでOK。
memcacheの起動

/etc/init.d/memcached start

サービスを自動起動にしておく。

chkconfig memcached on

テストスクリプト


<?php
    $cache = new Memcache;
    $key = 'cache_test';
    $cache->connect('localhost', 11211);
    if(!$cache->get($key)){
        // キャッシュの有効時間は15秒
        $cache->set($key, date('Y-m-d h:i:s'), MEMCACHE_COMPRESSED, 15);
    }
    echo $cache->get($key);
?>

php: Smartyのdate_formatで前のゼロを表示しない方法

Smartyのdate_formatで先頭に0をつけない月と日を出力するには、引数の書式指定部分にそれぞれ”-”(マイナス)を付ける。

{$mydate|date_format:'%-m:%-d'}

‘%m%d’なら’07/05′になる。
-をつけて’%-m:%-d’なら’7/5′になる。

php:PEAR phpunitのインストール

足りないPEARライブラリとphp-extensionを入れてから、phpunit/PHPUnitをインストール。

# pear install pear/Image_GraphViz
# pear install pear/Log
# yum install php-common
# yum install php-dom
# yum install php-pdo
# pear install phpunit/PHPUnit