A PHP extension for Facebook's RocksDB

來源:互聯網
上載者:User

標籤:

A PHP extension for Facebook‘s RocksDB
  •  31 commits
  •  2 branches
  •  0 releases
  •  2 contributors
  1.  C++ 90.5%
  2.  C 8.9%
  3.  Other 0.6%
C++COther branch: master rocksdb-php/

Merge pull request #1 from miclen/patch-1 …

latest commit 8b6542e285 Photonios authored on 25 Feb 2014
  src Update database.cpp a year ago
  test Revert 4c59e30 a year ago
  .gitignore Updated gitignore to ignore eclipse project files and other junk 2 years ago
  Makefile Revert 4c59e30 a year ago
  README.md Revert 4c59e30 a year ago
  test.sh Revert 4c59e30 a year ago
  test_valgrind.sh Revert 4c59e30 a year ago
 README.md

 

 

RocksDB PHP Extension

RocksDB is a new embedded database for storing key-value pairs developed by Facebook. This project hosts a PHP extension for RocksDB. More information on RocksDB can be found here:

https://github.com/facebook/rocksdb

Simple Example
<?php    $rocksdb = new RocksDB("my_rocksdb_file");    $result = $rocksdb->Open(true);    if($result)        die("Unable to open rocksdb!");    $rocksdb->Put("my_awesome_key", "my_awesome_value");    $value = $rocksdb->Get("my_awesome_key");    echo $value . "\n";?>

Check test/test.php for more examples.

Platforms

RocksDB is said to compile on Linux and Mac OS X. So far, I haven‘t seen anyone getting it to build on Windows, but it should work. My build environment is:

  • Ubuntu 13.10 x64
  • GCC 4.8.1

All documentation, instructions and guides assume my configuration. If you were able to get it working on another platform, please let me know.

Notes

I use a custom version of PHP-CPP, because I added basic exception support. Please checkout the fork, until my pull request has been accepted:

git clone https://github.com/Photonios/PHP-CPP
BuildBuilding RocksDB PHP Extension

Before trying to build the RocksDB PHP extension, make sure you have installed all dependencies listed below. After that, you can simply checkout the code:

git clone https://github.com/Photonios/rocksdb-php.git

Then, run make:

make

The PHP extension, which is a shared/dynamiclly linked library can be found in the bin directory.

Building PHP

The RocksDB PHP extension is being written against PHP 5.5.3. To be able to build the RocksDB PHP extension, you need to install the following packages:

sudo apt-get install php5-devsudo apt-get install php5-cli
Building PHP-CPP

PHP-CPP is a C++ library which makes developing PHP extensions from C++ possible. It‘s also, way easier then using the native PHP C API. PHP-CPP can be found here:

https://github.com/EmielBruijntjes/PHP-CPP

To build, clone the repository:

git clone https://github.com/EmielBruijntjes/PHP-CPP.git php-cpp

Go into the ‘php-cpp‘ directory and run:

make

After that, ‘libphpcpp.so‘ should be present in the ‘src‘ directory. To install the library, do one of the following thins:

  • Add the path where you cloned PHP-CPP to LD_LIBRARY_PATH (export LD_LIBRARY_PATH+=/path/to/php-cpp/src)
  • Create a new file in /etc/ld.so.conf.d with the .conf extension, where the path to the PHP-CPP src directory is on a single line
  • Copy the file libphpcpp.so to /usr/lib
Building RocksDB

To build the RocksDB PHP Extension, you first need to build RocksDB. Clone the RocksDB git repository using:

git clone https://github.com/facebook/rocksdb.git

To be able to build RocksDB, you first need to install all dependencies, this can be done using apt-get:

sudo apt-get install libsnappy-devsudo apt-get install zlib1g-devsudo apt-get install libbz2-devsudo apt-get install libgflags2sudo apt-get install libgflags-dev

Or run:

sudo apt-get install libsnappy-dev zlib1g-dev libbz2-dev libgflags2 libgflags-dev

After you‘ve install all dependencies, you can simply run:

make cleanmake

To build and run all unit tests:

make check

To install the RocksDB library you can do either of these three things:

  • Add the path where you cloned RocksDB to LD_LIBRARY_PATH (export LD_LIBRARY_PATH+=/path/to/rocksdb)
  • Create a new file in /etc/ld.so.conf.d with the .conf extension, where the path to RocksDB is on a single line
  • Copy the files librocksdb.a and libmemenv.a to /usr/lib

Choose whatever you like :)

Installation

After you build the RocksDB PHP extension, you should have a .so file in the bin directory. Execute:

php --ini

To find out where your PHP configuration file is located. It should output something liek this:

Loaded Configuration File:         /etc/php5/cli/php.ini

Find the line that starts with extension=, if it‘s commented out, uncomment it and set the path to your extension, like this:

extension=/iam_awesome/cookies/dance/in/the/rain/rocksdb-php.so

Then, enjoy :D

A PHP extension for Facebook's RocksDB

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.