PHP Classes

PHP MySQL Replication: Client to get MySQL replication events in pure PHP

Recommend this page to a friend!
  Info   View files Example   View files View files (1)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStarStar 87%Total: 754 All time: 4,456 This week: 108Up
Version License PHP version Categories
mysql-replication 2.0.28MIT/X Consortium ...5.6Networking, PHP 5, Databases
Description 

Author

Kacper Rowi?ski


Contributor

This package implements a client to get MySQL replication events in pure PHP.

It establishes a socket connection to a MySQL binary log server to so it can listen to MySQL database changes events like insert, update, delete queries with their data as well raw SQL queries.

The events can be dumped for debugging purposes or used to replicate the database on a new server.

Recommendations

extract updated data
I want a class that can sync localdatabase with online hosting

clone mysql BIG database
Clone mysql BIG databases without export/import, but copying

Innovation Award
PHP Programming Innovation award nominee
March 2016
Number 7


Prize: One subscription to the PDF edition of the PHP Architect magazine
MySQL supports replication of data, so multiple slave servers can store the same data as the master.

The replication is done using a networking protocol that can be used by slaves to retrieve data from the servers.

This package can act as a MySQL slave, so it can replicate data from a MySQL server in pure PHP.

Manuel Lemos
Picture of Kacper Rowinski
  Performance   Level  
Name: Kacper Rowinski <contact>
Classes: 14 packages by
Country: Poland Poland
Age: 39
All time rank: 92326 in Poland Poland
Week rank: 76 Up1 in Poland Poland Up
Innovation award
Innovation award
Nominee: 8x

Example

<?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();


  Files folder image Files  
File Role Description
Files folder imageexample (1 file)

  Files folder image Files  /  example  
File Role Description
  Accessible without login Plain text file dump_events.php Example Example script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:754
This week:0
All time:4,456
This week:108Up
 User Ratings  
 
 All time
Utility:100%StarStarStarStarStarStar
Consistency:95%StarStarStarStarStar
Documentation:91%StarStarStarStarStar
Examples:100%StarStarStarStarStarStar
Tests:91%StarStarStarStarStar
Videos:-
Overall:87%StarStarStarStarStar
Rank:2