在PHP中通过Hive/Trift查询数据库不起作用


Querying database through Hive/Thrift in PHP does not work

我正试图通过PHP中的Hive/Trift查询数据库。然而,我不断地得到一个错误:

TSocket: timed out reading 4 bytes from XYZ

我正在使用的代码

https://cwiki.apache.org/Hive/hiveclient.html#HiveClient-PHP

连同这个PHP Thrift客户端

https://github.com/garamon/php-thrift-hive-client

我的代码:

<?php
$socket    = new TSocket( 'XYZ', 12345 );
$socket->setSendTimeout(30 * 1000);
$socket->setRecvTimeout(30 * 1000);
$transport = new TBufferedTransport( $socket, 1024, 1024 );
$protocol  = new TBinaryProtocol( $transport );
$client    = new ThriftHiveClientEx( $protocol );
$transport->open();
$client->execute("my query");
?>

注意-我可以通过控制台(telnet命令)连接XYZ。

如果有任何帮助,我都会通知你的。谢谢

在使用完全相同的资源时,我也遇到了类似的问题。事实证明,代码无法识别它是否超时或是否阻塞了端口

https://issues.apache.org/jira/browse/THRIFT-347

在TSocket.php代码(garamon_base_dir/lib/transport)中,您必须编辑大约223到236行。

上面写着:

if( $buf === FALSE || $buf === '' ) { ...
and
if( $md['timed_out'] ) { ...
and then again
if( $md[timed_out'] ) { ...

更改为(分别):

if( $buf === FALSE ) { ...
and
if( true === $md['timed_out'] && false === $md['blocked'] )
and finally 
if( true === $md['timed_out'] && false === $md['blocked'] )

然后它在修复后开始工作。祝你好运