• 2013-01-01

    PHP working with LevelDB

    Views: 13283 | No Comments

    The Google LevelDB is a C/C++ key-value storage library, this means you can only write C/C++ code to use LevelDB. Unlike other key-value storage solution and MySQL, LevelDB doesn’t have a network server.

    If you wan your PHP code to work with LevelDB, you can either wrap LevelDB as a PHP module, or wrap LevelDB as a network server. Writing a PHP LevelDB module is not a good idea most of the time, because we always want to connect to one LevelDB from several machines across network.

    This is why I create SSDB – a LevelDB server with zset data type support. SSDB has a very simple network protocol, that can be implemented with many programming language, such as C, C++, PHP, Python, Cpy…

    Here is a example of PHP operates with SSDB(LevelDB):

    $ssdb = new SimpleSSDB('', 8888);
    $resp = $ssdb->set('key', '123');
    $resp = $ssdb->get('key');
    echo $resp; // output: 123

    Download SSDB from: https://github.com/ideawu/ssdb

    Posted by ideawu at 2013-01-01 01:16:20
  • 2012-12-27

    SSDB has made a big progress!

    Views: 10397 | No Comments

    SSDB v1.1.0 is released! This version added the Online Backup feature, which allows to backup a SSDB instance without stopping service.

    Quick Start

    ./tools/ssdb-dump 8888 backup_dir

    A copy of SSDB instance(it is also the leveldb database) will be saved in a new created directory backup_dir.


    Transfer the directory backup_dir to the server on which ssdb-server runs, then edit ssdb.conf to use backup_dir, restart ssdb-server.

    Next Step

    SSDB is now a productional storage server! The next feature that is planning to added is Replication(Master-Slave architecture). Replication is the base of distributed system.

    SSDB Project: https://code.google.com/p/zdb/

    Posted by ideawu at 2012-12-27 00:00:18 Tags: ,
  • 2012-12-18

    SSDB v1.0.1 supports more commands

    Views: 10001 | No Comments

    SSDB version 1.0.1 is released. In this version, more commands are supported, these commands are:

    keys, zkeys, hkeys, incr, decr, zincr, zdecr, hincr, hdecr

    SSDB is used as cache server on www.udpwork.com, it works very well! So, don’t doubt to use SSDB for your project.

    Posted by ideawu at 2012-12-18 00:36:19 Tags: ,
  • 2012-12-12

    SSDB – A leveldb server with zset data type

    Views: 15991 | No Comments

    The Google leveldb is just a c++ library, cannot be directly used by PHP/Java/Python. As it is a library, data can’t be accessed across multi machines(not even multiprocesses in one machine).

    SSDB(or zdb) is a network server that wrapping leveldb library, more important, besides key-value data type, SSDB supports zset(sorted set) and hash data type. Zset is the most valuable data type that widely used with Redis, to describe business abstracts such as inbox/outbox of a messaging system, posts list of a news site, etc.

    SSDB’s client APIs currently including PHP, Python, Cpy, and more can be added easily.

    Here is a list of SSDB features:

    • Network wrapping of Google leveldb, client-server supports
    • Persistent key-value, key-zset, key-hash storage
    • Very fast(benchmark)

    SSDB project: http://code.google.com/p/zdb/

    Posted by ideawu at 2012-12-12 11:15:58 Tags: ,
  • 2012-11-10

    Compiling levelDB on Windows Cygwin

    Views: 16047 | 1 Comment

    The official levelDB does not support Cygwin platform, trying to compile it on Cygwin may get the error message:”Unknow platform”. Anyway, levelDB works on Windows Cygwin environment, all you have to do is to manually modify some files.

    First, make sure your Cygwin has gcc-4 installed, not gcc-3:

    $ gcc -v
    gcc version 4.5.3 (GCC)

    Then, edit build_detect_platform under levelDB source code folder, make it looks like this:

    case "$TARGET_OS" in

    The “CYGWIN_*” codes is added. Then edit port/port_posix.h, make it looks like this:

    #if defined(OS_MACOSX) || defined(OS_SOLARIS) || defined(OS_FREEBSD) ||\
        defined(OS_NETBSD) || defined(OS_OPENBSD) || defined(OS_DRAGONFLYBSD) ||\
        defined(OS_ANDROID) || defined(OS_HPUX) || defined(CYGWIN)
    // Use fread/fwrite/fflush on platforms without _unlocked variants
    #define fread_unlocked fread
    #define fwrite_unlocked fwrite
    #define fflush_unlocked fflush

    The ” || defined(CYGWIN)” is added, or you may got this error if you try to run make:

    util/env_posix.cc:50: error: `fread_unlocked' undeclared (first use this function)

    Now, you can compile levelDB on Windows Cygwin:


    If you can find the file libleveldb.a in levelDB source code folder, it’s sucessfull. levelDB is just a library, not a standalone server, so we write a simple CPP code example to test it:

    #include <iostream>
    #include "leveldb/db.h"
    int main(){
        leveldb::DB* db;
        leveldb::Options options;
        leveldb::Status status;
        options.create_if_missing = true;
        status = leveldb::DB::Open(options, "./testdb", &db);
        std::string key = "abc";
        std::string value = "123";
        std::string ret;
        std::cout << value;
        status = db->Put(leveldb::WriteOptions(), key, value);
        status = db->Get(leveldb::ReadOptions(), key, &ret);
        std::cout << ret;
        return 0;

    Compile this code(file named a.cpp) and run with command:

    g++ a.cpp -Iinclude -L. -lleveldb; ./a
    Posted by ideawu at 2012-11-10 12:09:50 Tags: ,
|<<<1234>>>| 3/4 Pages, 16 Results.