Skip to content

Commit

Permalink
Merge pull request #3 in PH/phpkafka from intern-master to master
Browse files Browse the repository at this point in the history
* commit '9ae449d3be8298b5ef2312383c70c4a4eb47c5aa':
  Add test script + recompile script
  • Loading branch information
Elias Van Ootegem committed Apr 3, 2015
2 parents 4c06446 + 9ae449d commit 6b06954
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
11 changes: 11 additions & 0 deletions recompile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
CONF_FILE="configure"
if [ -e $CONF_FILE ] ; then
./configure clean
fi
make clean
phpize
./configure --enable-kafka
make
sudo make install

31 changes: 31 additions & 0 deletions test2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
$kafka = new \Kafka("kafka-1:9092,kafka-2:9092");
$topic = 'eliasTest';
$msg = 'this message was produced on ' . date('Y-m-d H:i:s');
printf(
'Producing message "%s" on topic "%s"' . PHP_EOL,
$msg,
$topic
);
$kafka->produce($topic, $msg);
echo 'Done', PHP_EOL;
echo 'Listing partitions for topic ', $topic, PHP_EOL
var_dump($kafka->getPartitionsForTopic('eliasTest'));
echo 'Closing, and reopening connection', PHP_EOL
$kafka = new \Kafka("kafka-1:9092,kafka-2:9092");
echo 'Done... Now selecting partition 2', PHP_EOL;
$kafka->setPartition(2);
$start = microtime(true);
$cons = $kafka->consume($topic, Kafka::OFFSET_BEGIN , Kafka::OFFSET_END);
$end = microtime(true);
$read = count($cons);
printf('Read all %d messages in %fms, or %f per message' . PHP_EOL,
$read,
$end - $start,
$read ? ($end - $start)/$read : 0
);
echo 'Dumping messages'
var_dump($cons);
echo 'Closing connection', PHP_EOL;
$kafka->disconnect();
echo 'Done', PHP_EOL;

0 comments on commit 6b06954

Please sign in to comment.