php-leveldb 扩展安装 和使用

本文详细介绍了如何安装并使用php-leveldb扩展进行数据存储和检索,包括下载、配置、修改php.ini及示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.测试一下

<?php
/* 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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值