php-leveldb 扩展安装 和使用

1. 首先下载安装leveldb

git clone https://github.com/google/leveldb.git
cd leveldb/
make

2.下载安装php扩展(注意修改自己的leveldb路径和php-config路径)

git clone https://github.com/reeze/php-leveldb.git
cd php-leveldb
phpize

./configure --with-leveldb=/home/eifel/Downloads/leveldb/include/leveldb --with-php-config=/usr/local/php/bin/php-config

make
make install

3.修改php.ini 增加 leveldb.so

4.测试一下


/* default open options */
$options = array(
        'create_if_missing' => true,    // if the specified database didn't exist will create a new one
        'error_if_exists'   => false,   // if the opened database exsits will throw exception
        'paranoid_checks'   => false,
        'block_cache_size'  => 8 * (2 << 20),
        'write_buffer_size' => 4<<20,
        'block_size'        => 4096,
        'max_open_files'    => 1000,
        'block_restart_interval' => 16,
        'compression'       => LEVELDB_SNAPPY_COMPRESSION,
        'comparator'        => NULL,   // any callable parameter which returns 0, -1, 1
);
/* default readoptions */
$readoptions = array(
        'verify_check_sum'  => false,
        'fill_cache'        => true,
        'snapshot'          => null
);

/* default write options */
$writeoptions = array(
        'sync' => false
);
//下面的/opt/youku/leveldb是一个目录
$db = new LevelDB("/opt/youku/leveldb", $options, $readoptions, $writeoptions);

$db->put("Key", "Value");
$value =$db->get("Key");
echo($value."\n");
$db->delete("Key");
$value =$db->get("Key");
echo($value."\n");

更详细的使用方法请参照php-leveldb扩展

https://github.com/reeze/php-leveldb

你可能感兴趣的:(php)