Database query via Hive / Thrift in PHP does not work

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

TSocket: timed out reading 4 bytes from XYZ 

I am using 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 is:

 <?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 can connect to XYZ through the console (telnet command).

I would advise any help. Thanks.

+4
source share
1 answer

I had a similar problem starting with the same resources. It turns out that the code does not recognize if it was disconnected or the port was blocked. I found this article that helped me:

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

In the TSocket.php code (garamon_base_dir / lib / transport) you should edit approximately lines 223 through 236.

Where does he say:

 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 he started working after this fix. Good luck

+2
source

Source: https://habr.com/ru/post/1490246/


All Articles