{"id":13813330,"url":"https://github.com/bullsoft/php-binlog","last_synced_at":"2026-01-11T13:04:29.676Z","repository":{"id":6640128,"uuid":"7884241","full_name":"bullsoft/php-binlog","owner":"bullsoft","description":"A PHP-Client for MySQL Binlog","archived":false,"fork":false,"pushed_at":"2017-06-16T05:53:42.000Z","size":145,"stargazers_count":188,"open_issues_count":2,"forks_count":51,"subscribers_count":28,"default_branch":"master","last_synced_at":"2024-11-19T08:46:43.516Z","etag":null,"topics":["mysql","mysql-replication-listener","php","php-binlog"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bullsoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-01-29T03:06:12.000Z","updated_at":"2024-07-09T09:48:17.000Z","dependencies_parsed_at":"2022-07-31T03:18:06.280Z","dependency_job_id":null,"html_url":"https://github.com/bullsoft/php-binlog","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bullsoft%2Fphp-binlog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bullsoft%2Fphp-binlog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bullsoft%2Fphp-binlog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bullsoft%2Fphp-binlog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bullsoft","download_url":"https://codeload.github.com/bullsoft/php-binlog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254251122,"owners_count":22039350,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mysql","mysql-replication-listener","php","php-binlog"],"created_at":"2024-08-04T04:01:13.136Z","updated_at":"2026-01-11T13:04:29.632Z","avatar_url":"https://github.com/bullsoft.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"PHP Binlog\n==========\n\n_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._\n      \n---------------------------------------\n\nA PHP-Client for mysql replication listener API.\n\nYou can use it to connect to a MYSQL server which produces BINLOG, and get BINLOG events in real-time, just like a Async-Trigger.\n\nYou 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.\n\nOur 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.\n\nDependence\n--------------------\n* MySQL Replication Listener Library (https://github.com/BullSoft/mysql-replication-listener)\n* PHP 5.3.X\n* MySQL 5.4 and lower,,,  for MySql 5.7, you can checkout the branch `bundle-new-binlog` and install the extension in `cpp_ext`.\n\nInstall\n--------------------\nFirst, install mysql-replication-listener.\n\n$ cmake . -DCMAKE_INSTALL_PREFIX=/home/work/mysql-replication\n\n$ make \u0026\u0026 make install\n\nThen change to php-binlog ext directory,\n\n$ /home/work/local/php/bin/phpize\n\n$ ./confingure --with-php-config=/home/work/local/php/bin/php-config --with-mysql-binlog=/home/work/mysql-replication\n\n$ make\n\n$ make install\n\nExample\n----------------\n注：Binlog为行格式\n\n```php\n$link = binlog_connect(\"mysql://root@127.0.0.1:3306\");\n// binlog_set_position($link, 4);                           \n\nwhile($event=binlog_wait_for_next_event($link)) {\n    // it will block here                                   \n    switch($event['type_code']) {\n        case BINLOG_DELETE_ROWS_EVENT:\n            var_dump($event);\n            // do what u want ...                           \n            break;\n        case BINLOG_WRITE_ROWS_EVENT:\n            var_dump($event);\n            // do what u want ...                           \n            break;\n        case BINLOG_UPDATE_ROWS_EVENT:\n            var_dump($event);\n            // do what u want ...                           \n            break;\n        default:\n            // var_dump($event);                            \n            break;\n    }\n}\n```\n\n### Update_rows\n\n```sql\nupdate `type` set type_id = 22 WHERE id in (58, 59);\n```\n```php\narray(5) {\n  'type_code' =\u003e\n  int(24)\n  'type_str' =\u003e\n  string(11) \"Update_rows\"\n  'db_name' =\u003e\n  string(5) \"cloud\"\n  'table_name' =\u003e\n  string(4) \"type\"\n  'rows' =\u003e\n  array(4) {\n    [0] =\u003e\n    array(5) {\n      [0] =\u003e\n      string(2) \"58\"\n      [1] =\u003e\n      string(8) \"adsfasdf\"\n      [2] =\u003e\n      string(4) \"asdf\"\n      [3] =\u003e\n      string(2) \"22\"\n      [4] =\u003e\n      string(1) \"0\"\n    }\n    [1] =\u003e\n    array(5) {\n      [0] =\u003e\n      string(2) \"58\"\n      [1] =\u003e\n      string(8) \"adsfasdf\"\n      [2] =\u003e\n      string(4) \"asdf\"\n      [3] =\u003e\n      string(1) \"4\"\n      [4] =\u003e\n      string(1) \"0\"\n    }\n    [2] =\u003e\n    array(5) {\n      [0] =\u003e\n      string(2) \"59\"\n      [1] =\u003e\n      string(8) \"adsfasdf\"\n      [2] =\u003e\n      string(4) \"asdf\"\n      [3] =\u003e\n      string(2) \"22\"\n      [4] =\u003e\n      string(1) \"0\"\n    }\n    [3] =\u003e\n    array(5) {\n      [0] =\u003e\n      string(2) \"59\"\n      [1] =\u003e\n      string(8) \"adsfasdf\"\n      [2] =\u003e\n      string(4) \"asdf\"\n      [3] =\u003e\n      string(1) \"4\"\n      [4] =\u003e\n      string(1) \"0\"\n    }\n  }\n}\n```\n### Delete_rows\n\n```sql\ndelete from `type` WHERE id in (58, 59);\n```\n\n```php\narray(5) {\n  'type_code' =\u003e\n  int(25)\n  'type_str' =\u003e\n  string(11) \"Delete_rows\"\n  'db_name' =\u003e\n  string(5) \"cloud\"\n  'table_name' =\u003e\n  string(4) \"type\"\n  'rows' =\u003e\n  array(2) {\n    [0] =\u003e\n    array(5) {\n      [0] =\u003e\n      string(2) \"58\"\n      [1] =\u003e\n      string(8) \"adsfasdf\"\n      [2] =\u003e\n      string(4) \"asdf\"\n      [3] =\u003e\n      string(2) \"22\"\n      [4] =\u003e\n      string(1) \"0\"\n    }\n    [1] =\u003e\n    array(5) {\n      [0] =\u003e\n      string(2) \"59\"\n      [1] =\u003e\n      string(8) \"adsfasdf\"\n      [2] =\u003e\n      string(4) \"asdf\"\n      [3] =\u003e\n      string(2) \"22\"\n      [4] =\u003e\n      string(1) \"0\"\n    }\n  }\n}\n```\n### Write_rows\n\n```sql\ninsert into type values (Null, \"Hello, World\", \"Best world\", 4, 0), (NULL, \"你好，世界\", \"世界很美好\", 3, 5);\n```\n\n```php\narray(5) {\n  'type_code' =\u003e\n  int(23)\n  'type_str' =\u003e\n  string(10) \"Write_rows\"\n  'db_name' =\u003e\n  string(5) \"cloud\"\n  'table_name' =\u003e\n  string(4) \"type\"\n  'rows' =\u003e\n  array(2) {\n    [0] =\u003e\n    array(5) {\n      [0] =\u003e\n      string(2) \"95\"\n      [1] =\u003e\n      string(12) \"Hello, World\"\n      [2] =\u003e\n      string(10) \"Best world\"\n      [3] =\u003e\n      string(1) \"4\"\n      [4] =\u003e\n      string(1) \"0\"\n    }\n    [1] =\u003e\n    array(5) {\n      [0] =\u003e\n      string(2) \"96\"\n      [1] =\u003e\n      string(15) \"你好，世界\"\n      [2] =\u003e\n      string(15) \"世界很美好\"\n      [3] =\u003e\n      string(1) \"3\"\n      [4] =\u003e\n      string(1) \"5\"\n    }\n  }\n}\n```\n\nReference\n--------------------\nMySQL Replication Listener:\n\nhttp://cdn.oreillystatic.com/en/assets/1/event/61/Binary%20log%20API_%20A%20Library%20for%20Change%20Data%20Capture%20using%20MySQL%20Presentation.pdf\n\nhttp://dev.mysql.com/doc/internals/en/index.html\n\nhttp://dev.mysql.com/doc/refman/5.1/en/mysqlbinlog-row-events.html\n\nhttp://dev.mysql.com/doc/internals/en/replication-protocol.html\n\n\n[![endorse](https://api.coderwall.com/cnwggu/endorsecount.png)](https://coderwall.com/cnwggu)\n\n\n\nFeedback\n-------------------------\n\nIssues and contributions are welcome.\n\nThank you!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbullsoft%2Fphp-binlog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbullsoft%2Fphp-binlog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbullsoft%2Fphp-binlog/lists"}