PHPからGroonga 
を使うにはこんな 
コードになるよ! 
2014/09/03 
ConoHa presents – 
Groonga "How-To" Talks 
do_aki
@do_aki 
@do_aki 
http://do-aki.net/
立場 
SIDE
このは派 
あんず派 
(C)GMO Internet, Inc.
あんず派 
(C)GMO Internet, Inc.
以上
access methods 
 HTTP 
 GQTP 
 Direct
access methods 
HTTP 
• socket・stream・curl 
• nise-nabe/groonga-http-php 
GQTP 
• socket (たぶんできる) 
• groonga-php (groonga bundle) 
Direct 
• phroonga (rsky) 
• proonga (Yujiro3)
HTTP
nise-nabe/groonga-http-php 
• guzzleを利用したgroonga http client 
• curl or stream 
• php >=5.3.0 
• packagist 
composer.json 
{ 
“require”: { 
"nise-nabe/groonga-http-php": "dev-master" 
} 
}
Sample Code 
• https://gist.github.com/do-aki/ 
419953a481d0289ffbbb 
• Client をnew してコマンドに対応し 
たメソッドを呼ぶ形 
• エラーは例外として補足できる 
• シンプル
GQTP
groonga-php 
• groonga bundle のgqtp client 
• fedora 用のRPM (野良?) => オフィシャルだそうです 
• php extension “groonga” 
$ cd [groonga-source-dir]/bindings/php 
$ phpize 
$ ./configure 
$ make 
$ php -d extension=modules/groonga.so sample.php
Sample Code 
• https://gist.github.com/do-aki/ 
d91584e38efd9f844d30 
• 最低限の実装 
• このままつかうのはシンドイ 
• エラー内容を補足できない
Direct
phroonga (php-extension) 
• https://github.com/rsky/phroonga 
• php extension “groonga” 
• 4系で動かなかったので手を入れた 
ふるんが! 
$ git clone https://github.com/do-aki/php-phroonga 
$ cd phroonga 
$ phpize 
$ ./configure 
$ make 
$ php -d extension=modules/groonga.so sample.php
Sample Code 
• https://gist.github.com/do-aki/ 
b855f211f5a301f60920 
• select 出来ない 
• 実用段階にない
proonga (php-extension) 
• https://github.com/Yujiro3/proonga 
• php extension “groonga” 
• サンプルとてもよさげ 
• CentOS6 上のphp5.5 で動かず…… 
• PHP Fatal error: Internal zval's 
can't be arrays, objects or 
resources in Unknown on line 0 
The PHP bindings of Groonga.
ここまでのまとめ 
HTTP => シンプルだけど使える 
GQTP => エラーを補足できない 
Direct => Umm…
現状HTTP 以外に 
選択肢なし
dooaki/php-phroonga 
• 今作ってるもの 
• php >= 5.5.0 
• trait (クラスに機能を付与) 
• 遅延評価(generatorを利用) 
• 各種プロトコルに対応可能 
(http 以外まだないケド) 
• Active Record like (にしようかなー) 
• https://github.com/do-aki/php-phroonga 
• (https://gist.github.com/do-aki/b36c64e066bb947ea825)
php の新しい 
機能を使ってみ 
たかっただけ 
まだまだ使い方や挙動含めインタフェース 
が大幅に変わる可能性高いので注意
まとめ 
• 今のところ、http でのアクセスが確実 
• パフォーマンス必要なら別言語かな…… 
(http とgqtp でどれだけ違うか判らないけど) 
• php でぐるんぐるんする人少ない? 
=> 第一人者になれるチャンス 
• dooaki/phroonga は気長にやるつもり
Question?
ありがとう 
ございました 
2014/09/03 
ConoHa presents – 
Groonga "How-To" Talks 
do_aki

PHP から Groonga を使うにはこんなコードになるよ!

Editor's Notes

  • #9 mroonga じゃないよ groonga だよ mroonga x php の記事は多いけど、 groonga x php の記事少ない
  • #10 http -> groonga (–s –d) --protocol http (--port 10041) gqtp -> groonga (–s –d) (--protocol gqtp) (--port 10043)