All Projects → bullsoft → Php Binlog

bullsoft / Php Binlog

A PHP-Client for MySQL Binlog

Labels

Projects that are alternatives of or similar to Php Binlog

Lzhpo Shiro
美观、漂亮,我抽离出来的,拿来即用的简单后台管理系统!
Stars: ✭ 170 (-5.03%)
Mutual labels:  mysql
Ruoyi
基于开源项目RuoYi-Vue,扩展开发添加新业务功能。基于SpringBoot,Spring Security,JWT,Vue & Element 的前后端分离权限管理系统
Stars: ✭ 174 (-2.79%)
Mutual labels:  mysql
Qxorm
QxOrm library - C++ Qt ORM (Object Relational Mapping) and ODM (Object Document Mapper) library - Official repository
Stars: ✭ 176 (-1.68%)
Mutual labels:  mysql
Linq2db
Linq to database provider.
Stars: ✭ 2,211 (+1135.2%)
Mutual labels:  mysql
Zebra
美团点评集团统一使用的MySQL数据库访问层的中间件。主要提供对业务开发透明、读写分库、分库分表能力,并提供了端到端SQL监控的集成方案。
Stars: ✭ 2,237 (+1149.72%)
Mutual labels:  mysql
Space Cloud
Open source Firebase + Heroku to develop, scale and secure serverless apps on Kubernetes
Stars: ✭ 3,323 (+1756.42%)
Mutual labels:  mysql
Rom Sql
SQL support for rom-rb
Stars: ✭ 169 (-5.59%)
Mutual labels:  mysql
Scalardb
Universal transaction manager
Stars: ✭ 178 (-0.56%)
Mutual labels:  mysql
Docker Compose Development
Clone and `bin/dev up`. Quickly start of developing locally with Nginx, PHP, Blackfire, Percona, Mailhog and Redis. Out of the box support for Magento2 Developer Box
Stars: ✭ 171 (-4.47%)
Mutual labels:  mysql
Nanodbc
A small C++ wrapper for the native C ODBC API | Requires C++14 since v2.12
Stars: ✭ 175 (-2.23%)
Mutual labels:  mysql
Spee.ch
An image hosting service on top of the LBRY protocol.
Stars: ✭ 171 (-4.47%)
Mutual labels:  mysql
Tsmean
Typescript-mysql-express-angular-node seed for your next web-app!
Stars: ✭ 173 (-3.35%)
Mutual labels:  mysql
Operators
Collection of Kubernetes Operators built with KUDO.
Stars: ✭ 175 (-2.23%)
Mutual labels:  mysql
Hibernate Reactive
A reactive API for Hibernate ORM, supporting non-blocking database drivers and a reactive style of interaction with the database.
Stars: ✭ 167 (-6.7%)
Mutual labels:  mysql
Mysql Sandbox
Quick and painless install of one or more MySQL servers in the same host.
Stars: ✭ 176 (-1.68%)
Mutual labels:  mysql
1backend
Run your web apps easily with a complete platform that you can install on any server. Build composable microservices and lambdas.
Stars: ✭ 2,024 (+1030.73%)
Mutual labels:  mysql
Scalable Wordpress Deployment On Kubernetes
This code showcases the full power of Kubernetes clusters and shows how can we deploy the world's most popular website framework on top of world's most popular container orchestration platform.
Stars: ✭ 173 (-3.35%)
Mutual labels:  mysql
Phinx Migrations Generator
A Migration Code Generator for Phinx
Stars: ✭ 178 (-0.56%)
Mutual labels:  mysql
Databases
Async database support for Python. 🗄
Stars: ✭ 2,602 (+1353.63%)
Mutual labels:  mysql
Guacamole Install Rhel 7
Apache Guacamole installation bash script for RHEL 7 and CentOS 7 including options for Nginx, HTTPS, SSL, LDAP, Let's Encrypt certificates and more
Stars: ✭ 174 (-2.79%)
Mutual labels:  mysql

PHP Binlog

We have deployed it in produtive enviroment, and I posted an article for it (but in Chinese), http://guweigang.com/blog/2013/11/18/mysql-binlog-in-realtime/. Hope it will help you.


A PHP-Client for mysql replication listener API.

You can use it to connect to a MYSQL server which produces BINLOG, and get BINLOG events in real-time, just like a Async-Trigger.

You know, we always need to use different components to do a good job, serve a good service. Just like we use MYSQL to storage all our data, use REDIS as a cache server, and use LUCENE as a search engine. The differences between MYSQL and other components will affect the sorting result, and therefore affect user experience, especially for time-sensitive service.

Our group use PHP to develop web projects. So if we have a PHP extension to do the data trigger job between different components, everything will be easy. This is what we do and why we do.

Dependence

Install

First, install mysql-replication-listener.

$ cmake . -DCMAKE_INSTALL_PREFIX=/home/work/mysql-replication

$ make && make install

Then change to php-binlog ext directory,

$ /home/work/local/php/bin/phpize

$ ./confingure --with-php-config=/home/work/local/php/bin/php-config --with-mysql-binlog=/home/work/mysql-replication

$ make

$ make install

Example

注:Binlog为行格式

$link = binlog_connect("mysql://[email protected]:3306");
// binlog_set_position($link, 4);                           

while($event=binlog_wait_for_next_event($link)) {
    // it will block here                                   
    switch($event['type_code']) {
        case BINLOG_DELETE_ROWS_EVENT:
            var_dump($event);
            // do what u want ...                           
            break;
        case BINLOG_WRITE_ROWS_EVENT:
            var_dump($event);
            // do what u want ...                           
            break;
        case BINLOG_UPDATE_ROWS_EVENT:
            var_dump($event);
            // do what u want ...                           
            break;
        default:
            // var_dump($event);                            
            break;
    }
}

Update_rows

update `type` set type_id = 22 WHERE id in (58, 59);
array(5) {
  'type_code' =>
  int(24)
  'type_str' =>
  string(11) "Update_rows"
  'db_name' =>
  string(5) "cloud"
  'table_name' =>
  string(4) "type"
  'rows' =>
  array(4) {
    [0] =>
    array(5) {
      [0] =>
      string(2) "58"
      [1] =>
      string(8) "adsfasdf"
      [2] =>
      string(4) "asdf"
      [3] =>
      string(2) "22"
      [4] =>
      string(1) "0"
    }
    [1] =>
    array(5) {
      [0] =>
      string(2) "58"
      [1] =>
      string(8) "adsfasdf"
      [2] =>
      string(4) "asdf"
      [3] =>
      string(1) "4"
      [4] =>
      string(1) "0"
    }
    [2] =>
    array(5) {
      [0] =>
      string(2) "59"
      [1] =>
      string(8) "adsfasdf"
      [2] =>
      string(4) "asdf"
      [3] =>
      string(2) "22"
      [4] =>
      string(1) "0"
    }
    [3] =>
    array(5) {
      [0] =>
      string(2) "59"
      [1] =>
      string(8) "adsfasdf"
      [2] =>
      string(4) "asdf"
      [3] =>
      string(1) "4"
      [4] =>
      string(1) "0"
    }
  }
}

Delete_rows

delete from `type` WHERE id in (58, 59);
array(5) {
  'type_code' =>
  int(25)
  'type_str' =>
  string(11) "Delete_rows"
  'db_name' =>
  string(5) "cloud"
  'table_name' =>
  string(4) "type"
  'rows' =>
  array(2) {
    [0] =>
    array(5) {
      [0] =>
      string(2) "58"
      [1] =>
      string(8) "adsfasdf"
      [2] =>
      string(4) "asdf"
      [3] =>
      string(2) "22"
      [4] =>
      string(1) "0"
    }
    [1] =>
    array(5) {
      [0] =>
      string(2) "59"
      [1] =>
      string(8) "adsfasdf"
      [2] =>
      string(4) "asdf"
      [3] =>
      string(2) "22"
      [4] =>
      string(1) "0"
    }
  }
}

Write_rows

insert into type values (Null, "Hello, World", "Best world", 4, 0), (NULL, "你好,世界", "世界很美好", 3, 5);
array(5) {
  'type_code' =>
  int(23)
  'type_str' =>
  string(10) "Write_rows"
  'db_name' =>
  string(5) "cloud"
  'table_name' =>
  string(4) "type"
  'rows' =>
  array(2) {
    [0] =>
    array(5) {
      [0] =>
      string(2) "95"
      [1] =>
      string(12) "Hello, World"
      [2] =>
      string(10) "Best world"
      [3] =>
      string(1) "4"
      [4] =>
      string(1) "0"
    }
    [1] =>
    array(5) {
      [0] =>
      string(2) "96"
      [1] =>
      string(15) "你好,世界"
      [2] =>
      string(15) "世界很美好"
      [3] =>
      string(1) "3"
      [4] =>
      string(1) "5"
    }
  }
}

Reference

MySQL Replication Listener:

http://cdn.oreillystatic.com/en/assets/1/event/61/Binary%20log%20API_%20A%20Library%20for%20Change%20Data%20Capture%20using%20MySQL%20Presentation.pdf

http://dev.mysql.com/doc/internals/en/index.html

http://dev.mysql.com/doc/refman/5.1/en/mysqlbinlog-row-events.html

http://dev.mysql.com/doc/internals/en/replication-protocol.html

endorse

Feedback

Issues and contributions are welcome.

Thank you!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].