Fetch the repository succeeded.
<?php
namespace example;
error_reporting(E_ALL);
date_default_timezone_set('PRC');
include __DIR__ . '/vendor/autoload.php';
use MySQLReplication\Config\ConfigService;
use MySQLReplication\Event\DTO\EventDTO;
use MySQLReplication\Event\EventSubscribers;
use MySQLReplication\MySQLReplicationFactory;
$binLogStream = new MySQLReplicationFactory(
(new ConfigService())->makeConfigFromArray([
'user' => 'root',
'host' => '127.0.0.1',
'password' => '123456',
'binLogFileName' => __DIR__."/binlog.bin",
'slaveId' => 2,
//'mariaDbGtid' => '1-1-3,0-1-88',
//'gtid' => '9b1c8d18-2a76-11e5-a26b-000c2976f3f3:1-177592',
])
);
/**
* Class BenchmarkEventSubscribers
* @package example
*/
class MyEventSubscribers extends EventSubscribers
{
/**
* @param EventDTO $event (your own handler more in EventSubscribers class )
*/
public function allEvents(EventDTO $event)
{
// all events got __toString() implementation
echo $event;
// all events got JsonSerializable implementation
echo json_encode($event, JSON_PRETTY_PRINT);
echo 'Memory usage ' . round(memory_get_usage() / 1048576, 2) . ' MB' . PHP_EOL;
}
}
// register your events handler here
$binLogStream->registerSubscriber(new MyEventSubscribers());
// start consuming events
while (1) {
$binLogStream->binLogEvent();
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。