簡體   English   中英

在PHP中通過Hive / Thrift查詢數據庫不起作用

[英]Querying database through Hive/Thrift in PHP does not work

我正在嘗試通過PHP中的Hive / Thrift查詢數據庫。 但是,我經常遇到錯誤:

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'] )

然后在此修復程序之后開始工作。 祝好運!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM