andreiz / php-zookeeper

A PHP extension for interfacing with Apache ZooKeeper
Other
449 stars 215 forks source link

Zookeeper::exists(): error: invalid zhandle state #80

Open airanvinay opened 7 years ago

airanvinay commented 7 years ago

Getting Exception "Zookeeper::exists(): error: invalid zhandle state", I am using Zookeeper for Kafka. Need help to find out where i am wrong.

Timandes commented 7 years ago

Would you please paste your code?

dsewnr commented 7 years ago

I got same error, too.

PHP Warning: array_merge(): Argument #1 is not an array in /app/test_kafka/mq/vendor/nmred/kafka-php/src/Kafka/Produce.php on line 136 PHP Warning: Zookeeper::exists(): error: invalid zhandle state in /app/test_kafka/mq/vendor/nmred/kafka-php/src/Kafka/ZooKeeper.php on line 208

my code:

$queue = msg_get_queue( $queue_id );

$msg_type = NULL;
$msg = NULL;
$max_msg_size = 16384;

$kafka = \Kafka\Produce::getInstance(KAFKA_SERVER, KAFKA_TIMEOUT);
$kafka->setRequireAck(-1);

while( msg_receive($queue, 1, $msg_type, $max_msg_size, $msg) )
{
   $msg->mq_data[ 'ymd' ] = date( 'Ymd' );
   $json_data = json_encode( $msg->mq_data );

   try {
       $kafka->setMessages(TEST_KAFKA_TOPIC_PREFIX.date('Ymd'), rand(0,99), $json_data);
       $kafka->send();
       $kafka->setMessages(TEST_KAFKA_TOPIC_CURRENT, rand(0,99), $json_data);
       $kafka->send();
   } catch( \Exception $e ) {
       echo "...failed, passed.\n";
   }

   $msg_type = NULL;
   $msg = NULL;
}
Timandes commented 7 years ago

If you use latest version of pecl/zookeeper, you will get an exception when ' invalid zhandle state' occurs.

You can contact the author of nmred/kafka-php to catch this exception.

Timandes commented 6 years ago

Can we close this issue now? : )

dsewnr commented 6 years ago

Sure. ;p