PHP code example of phpone / canal_php

1. Go to this page and download the library: Download phpone/canal_php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phpone / canal_php example snippets


return [
    // server相关配置
    "server" => [
        // server地址
        "address" => '127.0.0.1',
        // 端口号
        "port" => 11111,
        // server配置destination
        "destination" => "example",
        "username" => "",
        "password" => "",
        // 订阅规则 db.table
        "filter" => "test.user",
        // clientid 默认值
        "clientId" => 1001,
    ],
    //每次拉取的数量值
    "batchSize" => 100,
    // 空循环次数
    "maxWhileCount" => 100,
    // 是否打印message 开启后消息将输出到console
    "openMessagePrint" => true,
    // 业务处理逻辑写到这里 参考test目录即可
    "messageCallback" => [\PhpOne\CanalPHP\Test\MessageHandle::class, "handle"],
    // 处理tcp粘包 参照swoole配置  
    // https://wiki.swoole.com/#/learn?id=tcp%e7%b2%98%e5%8c%85%e9%97%ae%e9%a2%98
    "client" => [
        'open_length_check' => 1, // 是否开启包长度检测
        "package_length_offset" => 0, // 从哪个字节开始算包长,如果总长度包含包头,就从0开始
        "package_body_offset" => 4, // 哪个字节的值代表包体长度
        'package_length_type' => 'N' // 解包方式  N 代表32位  参考pack unpack函数
    ]
];

shell
composer 
shell
php bin/start.php