问题描述:

I'm trying to query a database through Hive/Thrift in PHP. However, I am constantly getting an error:

TSocket: timed out reading 4 bytes from XYZ

I'm using a code from

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

along with this PHP Thrift Client

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

My code:

<?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");

?>

Note - I am able to connect with XYZ through console (telnet command).

I would appriciate any help. Thanks.

网友答案:

I had a similar problem when starting with those exact same resources. It turns out the code is not recognizing whether it has timed out or whether it is blocking the port. I found this article which helped me:

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

In your TSocket.php code ( garamon_base_dir/lib/transport ) you have to edit approximately lines 223 through 236.

Where it says:

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

change to (respectively):

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

Then it started working after this fix. Good luck!

相关阅读:
Top