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.

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

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效