File: example/dump_events.php

Recommend this page to a friend!
  Classes of Kacper Rowinski  >  PHP MySQL Replication  >  example/dump_events.php  >  Download  
File: example/dump_events.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP MySQL Replication
Client to get MySQL replication events in pure PHP
Author: By
Last change: Update dump_events.php

wrong repo link
Feature/php71 (#53)

- Removed: support for lesser then php7
- Added: strong and string types
- Changed: ConfigFactory removed and method make form array moved to Config
- Changed: MariaDbGtidLogDTO replaced getSequenceNumber with getMariaDbGtid
- Fixed: Insert NULL in a boolean column returns no rows
- Fixed: float problem about time field type
- Fixed: column order
- Changed: getFields and getMasterStatus returns no VO
- Changed: Column to ColumnDTO and added ColumnDTOCollection
- Changed: replaced getFields with getColumnDTOCollection in TableMap
- Added: more compatibility for mysql 5.5, 5.6, 5.7, maria 10 and 8.0
- Removed: makeConfigFromArray
Date: 9 months ago
Size: 1,298 bytes
 

Contents

Class file image Download
<?php
declare(strict_types=1);

error_reporting(E_ALL);
date_default_timezone_set('UTC');
include
__DIR__ . '/../vendor/autoload.php';

use
MySQLReplication\Config\ConfigBuilder;
use
MySQLReplication\Event\DTO\EventDTO;
use
MySQLReplication\Event\EventSubscribers;
use
MySQLReplication\MySQLReplicationFactory;

/**
 * Your db configuration
 * @see ConfigBuilder
 * @link https://github.com/krowinski/php-mysql-replication/blob/master/README.md
 */
$binLogStream = new MySQLReplicationFactory(
    (new
ConfigBuilder())
        ->
withUser('root')
        ->
withHost('127.0.0.1')
        ->
withPassword('root')
        ->
withPort(3306)
        ->
withSlaveId(100)
        ->
withHeartbeatPeriod(2)
        ->
build()
);

/**
 * Register your events handler
 * @see EventSubscribers
 */
$binLogStream->registerSubscriber(
    new class() extends
EventSubscribers
   
{
        public function
allEvents(EventDTO $event): void
       
{
           
// 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;
        }
    }
);

// start consuming events
$binLogStream->run();


For more information send a message to info at phpclasses dot org.