| 32 | |
| 33 | You should now have a fresh Thrift installation. We now need to generate PHP files that will be included in your application in order to access Hbase. |
| 34 | |
| 35 | {{{ |
| 36 | $ cp -r /opt/hbase/src/java/org/apache/hadoop/hbase/thrift ./hbase_thrift_src |
| 37 | $ cd hbase_thrift_src |
| 38 | $ thrift --gen php Hbase.thrift |
| 39 | }}} |
| 40 | |
| 41 | If you have followed all above the steps correctly, Thrift should have generated a directory named gen-php/Hbase/ wich contains 2 php files. Those two files contains classes you will use to access hbase. But those files also depends on Thrift base files that you can find in thrift source directory. Following steps assume that your apache home directory is /var/www. Let's copy Thrift base files and create a "packages" directory wich will contains previously generated files. |
| 42 | |
| 43 | {{{ |
| 44 | $ cp -r /opt/thrift-0.2.0/lib/php/src /var/www/thrift |
| 45 | (請記得改/var/www下的權限) |
| 46 | $ mkdir /var/www/thrift/packages |
| 47 | $ cp -r hbase_thrift_src/gen-php/* /var/www/thrift/packages/ |
| 48 | }}} |
| 49 | |
| 50 | Let's now start Hbase thrift server. |
| 51 | {{{ |
| 52 | $ /opt/hbase/bin/hbase thrift start & |
| 53 | }}} |
| 54 | |
| 55 | == test == |
| 56 | |
| 57 | {{{ |
| 58 | $ cp /opt/hbase/src/examples/thrift/DemoClient.php /var/www/DemoClient.php |
| 59 | }}} |
| 60 | |
| 61 | 修改 /var/www/DemoClient.php 的 |
| 62 | {{{ |
| 63 | #!text |
| 64 | $GLOBALS['THRIFT_ROOT'] = '/var/www/thrift'; |
| 65 | |
| 66 | $socket = new TSocket( 'secuse.nchc.org.tw', 9090 ); |
| 67 | }}} |
| 68 | |
| 69 | == 參考 == |
| 70 | |
| 71 | [http://appaquet.blogspot.com/2008/11/thrift-hbase-php.html André-Philippe Paquet's Blog] |
| 72 | |
| 73 | |
| 74 | == 除錯 == |
| 75 | |
| 76 | * 出現錯誤訊息 |
| 77 | {{{ |
| 78 | #!php |
| 79 | PHP Warning: Module 'mcrypt' already loaded in Unknown on line 0 |
| 80 | <html> |
| 81 | <head> |
| 82 | <title>DemoClient</title> |
| 83 | </head> |
| 84 | <body> |
| 85 | <pre> |
| 86 | scanning tables... |
| 87 | creating table: demo_table |
| 88 | column families in demo_table: |
| 89 | column: entry, maxVer: 10 |
| 90 | column: unused, maxVer: 3 |
| 91 | |
| 92 | Fatal error: Uncaught exception 'Exception' with message 'shouldn't get here!' in /var/www/DemoClient.php:158 |
| 93 | Stack trace: |
| 94 | #0 {main} |
| 95 | thrown in /var/www/DemoClient.php on line 158 |
| 96 | }}} |