日度归档:2012年3月5日

xcode4.3开启gcc/g++

真的坑爹,今天才开始玩MAC OX,装了个最新版本的10.7.3,只能装XCODE 4.3 这个月刚发行的版本。
安装时发现没有install过程,直接双击就进入开发环境了。而且装完后没有gcc 等各种编译工具,在TERMINAL下各种命令不识别,想装ruby的各种开发工具,都不行了。

查了半天才发现:
Apple announced Xcode 4.3 for OSX Lion and 4.4 for OSX Mountain Lion last week. The major difference is that Xcode no longer provide an installer which is good thing because you now could update Xcode with AppStore in the future, plus it is much easier to carry the development environment with you. However, there is a little problem with this new version of Xcode, is that all command line toolsets and compilers are not visible in terminal.

解决方案一:
A simple fix is to update your PATH env:
export PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:$PATH
Please be noted that clang does not reside in /Developer/usr/bin, it is now in /Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Now you could access to gcc, g++, git or any toolsets bundled with Xcode. For your convenience, it is recommended to include it in your .bash_profile.
解决方案二:
You can install these additional tools directly in Xcode :
Preferences > Downloads > Command Line Tools > Install

于 PHP 安装使用 Google LevelDB extension

LevelDB (leveldb – a fast and lightweight key/value database library) 是 Google 开发非常快速的 key-value 储存的函式库, 效能看起来相当不错: LevelDB Benchmarks, 且 LevelDB 的资料, 都会经过 Snappy 压缩, 所以资料也会比较小.

注: 下述安装环境为 Debian / Ubuntu Linux

于 PHP 增加 Google LevelDB 的 Extension

有 LevelDB 的 Source code, 再来找 PHP 的 ext 是否有人写, 于是就找到: leveldb for php

也正好找到此篇有人已经有做过编译: 从原始码编译 Google LevelDb 的 PHP 扩展, 下述步骤摘录自此篇.

安装、编译步骤
  1. BUILD=/usr/local/
  2. # 编译安装 LevelDB
  3. svn export http://leveldb.googlecode.com/svn/trunk/ leveldb
  4. cd $BUILD/leveldb
  5. make -j8 OPT=”-O2 -DNDEBUG -fPIC”
  6. # 编译安装 php-leveldb ext
  7. git clone git://github.com/arraypad/php-leveldb.git
  8. cd $BUILD/php-leveldb
  9. phpize
  10. ./configure –with-leveldb=$BUILD/leveldb
  11. make -j8
  12. make test
  13. make install
  14. # 于 Apache 的 PHP 设定 leveldb.so (extenstion)
  15. vim /etc/php5/cli/conf.d/leveldb.ini # 内容如下述
    extension=leveldb.so
  16. /etc/init.d/apache2 restart # 到此就可以开始使用 LevelDB 囉~

LevelDB 于 PHP 的操作与使用范例

范例可于 php-leveldb 的 tests 里面找到: basic.phpt (下述参考整理自此档案)

范例
<?php
if (!extension_loaded('leveldb')) {
    die('skip leveldb not loaded');
}

$path = '/tmp/leveldb.test';
$db = new LevelDb($path);

echo "* setting (foo=bar): \n";
var_dump($db->set('foo', 'bar')); // bool(true)

echo "* getting (foo): \n";
var_dump($db->get('foo')); // string(3) "bar"

echo "* delete (foo): \n";
var_dump($db->delete('foo')); // bool(true)

echo "* getting (foo): \n";
var_dump($db->get('foo')); // bool(false)
?>