Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('../lib/avro.php');
- function create_record() {
- $rec = array('member_id' => 1392, 'member_id2' => 999);
- for ($i = 0; $i < 20; $i++) {
- $rec['field' . $i] = 'test_value' . $i;
- }
- return $rec;
- }
- function create_writer() {
- $schema_json = <<<_JSON
- {"name":"member",
- "type":"record",
- "fields":[
- {"name":"member_id", "type":"int"},
- _JSON;
- for ($i = 0; $i < 20; $i++) {
- $schema_json .= '{"name":"field' . $i . '", "type":"string"},';
- }
- $schema_json .= '{"name":"member_id2", "type":"int"}]}';
- $schema = AvroSchema::parse($schema_json);
- $writer = new AvroIODatumWriter($schema);
- return $writer;
- }
- for ($i = 0; $i < 10000; $i++) {
- $writer = apc_fetch("writer");
- if ($writer === false) {
- $writer = create_writer();
- apc_store("writer", $writer);
- }
- $io = new AvroStringIO();
- $encoder = new AvroIOBinaryEncoder($io);
- $writer->write(create_record(), $encoder);
- $binary_string = $io->string();
- // file_put_contents("/tmp/avro.log", $binary_string, FILE_APPEND);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement