PHP无法在Percona群集上捕获MySQL binlog事件

问题描述

在这里使用此软件包:https://github.com/krowinski/php-mysql-replication

我已经能够在本地MysqL数据库上测试一个非常简单的应用程序,并且可以按预期运行。

但是,一旦我将测试转移到生产系统中,它似乎已停止工作。

现在,我的本地系统和生产之间存在一些自然差异,下面将对此进行概述。

  • PHP版本:7.4.9
  • MysqL版本:5.7.30-33-57-log Percona XTradB集群(GPL),rel33版本,修订版5dd6d59,WSREP版本31.43,wsrep_31.43
MysqL> SHOW variables WHERE variable_name LIKE "%binlog%";
+--------------------------------------------+----------------------+
| Variable_name                              | Value                |
+--------------------------------------------+----------------------+
| binlog_cache_size                          | 32768                |
| binlog_checksum                            | CRC32                |
| binlog_direct_non_transactional_updates    | OFF                  |
| binlog_error_action                        | ABORT_SERVER         |
| binlog_format                              | ROW                  |
| binlog_group_commit_sync_delay             | 0                    |
| binlog_group_commit_sync_no_delay_count    | 0                    |
| binlog_gtid_simple_recovery                | ON                   |
| binlog_max_flush_queue_time                | 0                    |
| binlog_order_commits                       | ON                   |
| binlog_row_image                           | FULL                 |
| binlog_rows_query_log_events               | OFF                  |
| binlog_skip_flush_commands                 | OFF                  |
| binlog_space_limit                         | 0                    |
| binlog_stmt_cache_size                     | 32768                |
| binlog_transaction_dependency_history_size | 25000                |
| binlog_transaction_dependency_tracking     | COMMIT_ORDER         |
| encrypt_binlog                             | OFF                  |
| have_backup_safe_binlog_info               | YES                  |
| innodb_api_enable_binlog                   | OFF                  |
| innodb_locks_unsafe_for_binlog             | OFF                  |
| log_statements_unsafe_for_binlog           | ON                   |
| max_binlog_cache_size                      | 18446744073709547520 |
| max_binlog_files                           | 0                    |
| max_binlog_size                            | 1073741824           |
| max_binlog_stmt_cache_size                 | 18446744073709547520 |
| sync_binlog                                | 1                    |
| wsrep_forced_binlog_format                 | NONE                 |
+--------------------------------------------+----------------------+
28 rows in set (0.00 sec)
MysqL> SHOW variables WHERE variable_name LIKE "server_%";
+----------------+--------------------------------------+
| Variable_name  | Value                                |
+----------------+--------------------------------------+
| server_id      | 3                                    |
| server_id_bits | 32                                   |
| server_uuid    | 4fe64515-be6b-11e9-8e7f-026f00293d26 |
+----------------+--------------------------------------+
3 rows in set (0.00 sec)

应用程序本身非常简单。它连接到数据库,侦听任何和所有binlog事件,然后在运行时将它们转储到控制台:

<?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\DeFinitions\ConstEventsNames;
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('<DB_USER>')
        ->withHost('127.0.0.1')
        ->withPassword('<DB_PASS>')
        ->withPort(3306)
        ->withSlaveId(100)
        ->withHeartbeatPeriod(2)
        ->build()
);

/**
 * Register your events handler
 * @see EventSubscribers
 */
$binlogStream->registerSubscriber(
    new class() extends EventSubscribers
    {
        /**
         * @param EventDTO $event
         */
        public function allEvents(EventDTO $event): void
        {
            $data = json_encode($event);

            /**
             * log the event.
             */
            echo json_encode($event);
        }
    }
);

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

当应用程序实际运行时,引发的唯一事件是无限重复的心跳事件:

{
    "type": "heartbeat","eventInfo": {
        "timestamp": 0,"type": 27,"id": 3,"size": 39,"pos": 11890,"flag": 0,"checkSum": true,"sizeNoHeader": null,"dateTime": null,"binlogCurrent": {
            "binlogPosition": 11890,"binFileName": "MysqL-bin.000016","gtid": null,"mariaDbGtid": null
        }
    },"subject": null,"arguments": null
}{
    "type": "heartbeat","arguments": null
}
...

奇怪的是,无论捕获了多少心跳事件(包括几天),binlog文件信息都不会改变。

数据库集群节点肯定是实时更新的,但未捕获事件。

寻找有关问题根源的任何想法。我怀疑这是配置问题,但是我不确定这可能是什么。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)