dongzengzai4567 2012-01-13 23:27
浏览 87
已采纳

Cassandra通过PHP

I have a client / server setup for Cassandra that works when accessed via Perl. Im trying to redo the process in PHP now. I can't seem to call any functions against my installation without getting a 'TSocket read 0 bytes' exception. Here is a sample that should be pretty straightforward:

$GLOBALS['THRIFT_ROOT'] = '/usr/local/src/thrift-0.8.0/lib/php/src';

require_once $GLOBALS['THRIFT_ROOT'].'/packages/cassandra/Cassandra.php';
require_once $GLOBALS['THRIFT_ROOT'].'/packages/cassandra/cassandra_types.php';
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TSocket.php';
require_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php';
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TFramedTransport.php';
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TBufferedTransport.php';

try {
 $socket = new TSocket( '10.127.24.19', 9160 );
 $transport = new TBufferedTransport( $socket, 1024, 1024 );
 $protocol = new TBinaryProtocolAccelerated( $transport );
 $client = new cassandra_CassandraClient( $protocol );
 $transport->open();

 $keyspace = 'some_data';

 $client->set_keyspace( $keyspace );

} 
catch (TException $tx)
{
   error_log( print_r( $tx, true ));
}  

This is thrift 0.8.0, Cassandra 1.0, PHP 5.3.1.

  • 写回答

1条回答 默认 最新

  • dongshang6062 2012-01-13 23:34
    关注

    Don't use raw thrift, use a library instead:

    You will hit a never-ending list of gotcha's like this otherwise.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题
  • ¥15 有没有人能解决下这个问题吗,本人不会编程
  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗