PHPackages                             phpone/canal\_php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. phpone/canal\_php

ActiveLibrary[API Development](/categories/api)

phpone/canal\_php
=================

canal php client

1.0.1(5y ago)011MITPHPPHP &gt;=7.2

Since Sep 16Pushed 5y ago1 watchersCompare

[ Source](https://github.com/nobody05/canal_php)[ Packagist](https://packagist.org/packages/phpone/canal_php)[ RSS](/packages/phpone-canal-php/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (4)Versions (4)Used By (0)

canal\_php
==========

[](#canal_php)

canal php client

Install
-------

[](#install)

```
composer require phpone/canal_php
```

使用
--

[](#使用)

- config/canal.php 文件复制到项目目录，并修改自己的配置
- test/bin/start.php 文件复制到项目目录, 请根据项目目录层级注意修改start.php的相应目录 BASE\_DIR、CONFIG\_DIR

启动
--

[](#启动)

```
php bin/start.php
```

请使用supervisor配置脚本，防止异常退出

配置说明
----

[](#配置说明)

```
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函数
    ]
];
```

目录说明
----

[](#目录说明)

- config 项目配置文件，自定义即可
- src
    - CanalClient 处理脚本
    - ClientIdentity 客户端类
    - Config 读取config/目录中的配置
    - Message 接收消息列表
    - PacketUtil 工具包
- test 测试
    - bin 启动脚本
    - MessageHandler 业务处理逻辑，自定义即可

处理逻辑
----

[](#处理逻辑)

主要处理流程根据java版的canal\_client参考来完成，其实就是c/s完成tcp数据传输的过程，我们需要了解

- protocolBuf的基本使用,这是一种跨语言的序列化协议，跟json、xml是一个意思
- canalServer中netty对于tcp的包处理，固定包头+包体 FixedLengthFrameDecoder解码器的原理
- 通信的流程client-&gt;protocol-&gt;tcp-&gt;server-&gt;tcp-&gt;protocol-&gt;client

参考项目
----

[](#参考项目)

- java client :
- php client:
- swoole client :

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

2070d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/570779d44e0341e6c338759362c311245f3b981d8b41b70e4b6c3ef723d79572?d=identicon)[nobody1990](/maintainers/nobody1990)

---

Top Contributors

[![nobody05](https://avatars.githubusercontent.com/u/18477825?v=4)](https://github.com/nobody05 "nobody05 (1 commits)")

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/phpone-canal-php/health.svg)

```
[![Health](https://phpackages.com/badges/phpone-canal-php/health.svg)](https://phpackages.com/packages/phpone-canal-php)
```

###  Alternatives

[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)[google/grpc-gcp

gRPC GCP library for channel management

18497.8M3](/packages/google-grpc-gcp)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)[googleads/google-ads-php

Google Ads API client for PHP

3497.6M9](/packages/googleads-google-ads-php)[temporal/sdk

Temporal SDK

4002.2M18](/packages/temporal-sdk)[netflie/whatsapp-cloud-api

The first PHP SDK to send and receive messages using a cloud-hosted version of the WhatsApp Business Platform

640431.7k4](/packages/netflie-whatsapp-cloud-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
