PHPackages                             sett/dtmcli-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. sett/dtmcli-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sett/dtmcli-php
===============

v1.0.3(3y ago)81.4k4MITPHP

Since Dec 11Pushed 2y ago2 watchersCompare

[ Source](https://github.com/kxg3030/shermie-dtmcli-php)[ Packagist](https://packagist.org/packages/sett/dtmcli-php)[ RSS](/packages/sett-dtmcli-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (5)Used By (0)

dtmcli-php
-------------------------

[](#dtmcli-php)

[![license](https://camo.githubusercontent.com/ee6c14da1134ee29735b6a371dbecd9c80f6ff93172233bdbd700b710dbce13a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6b7867333033302f64746d636c692d706870)](https://camo.githubusercontent.com/ee6c14da1134ee29735b6a371dbecd9c80f6ff93172233bdbd700b710dbce13a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6b7867333033302f64746d636c692d706870)

### 项目介绍

[](#项目介绍)

支持[DTM跨语言分布式事务管理](https://dtm.pub)所编写的php客户端，只支持http调用

### 支持事务类型

[](#支持事务类型)

- Tcc事务和子事务嵌套
- Xa事务
- 消息事务
- Saga事务
- 子事务屏障

### 安装

[](#安装)

```
composer require sett/dtmcli-php
```

### 示例

[](#示例)

- tcc

    ```
    // 127.0.0.1:36789为dtm默认端口
    $trans   = new TccTrans("127.0.0.1:36789");
    // 获取新事务ID
    $gid     = $trans->createNewGid();
    // 事务操作
    $success = $trans->withOperate($gid, function (TccTrans $tccTrans) use ($baseUrl) {
        $result = $tccTrans->callBranch(
            ["amount" => 30],
            "$baseUrl/dtm/tcc/transOut",
            "$baseUrl/dtm/tcc/transOutConfirm",
            "$baseUrl/dtm/tcc/transOutCancel"
        );
        if (!$result) {
            echo "call branch fail\n";
            return false;
        }
        return $tccTrans->callBranch(
            ["amount" => 30],
            "$baseUrl/dtm/tcc/transIn",
            "$baseUrl/dtm/tcc/transInConfirm",
            "$baseUrl/dtm/tcc/transInCancel"
        );
    });
    ```
- saga

    ```
    $trans = new SagaTrans("127.0.0.1:36789");
    $gid   = $trans->createNewGid();
    $trans
        ->withGid($gid)
        ->withOperate("$baseUrl/dtm/saga/transOut", "$baseUrl/dtm/saga/transOutRevert", ["amount" => 30])
        ->withOperate("$baseUrl/dtm/saga/transIn", "$baseUrl/dtm/saga/transInRevert", ["amount" => 30]);
    $success = $trans->submit();
    ```
- 事务消息

    ```
    $trans = new MsgTrans("127.0.0.1:36789");
    $gid   = $trans->createNewGid();
    $trans
        ->withOperate("$baseUrl/dtm/msg/transOut", ["amount" => 30])
        ->withOperate("$baseUrl/dtm/msg/transIn", ["amount" => 30])
        ->withQueryUrl("$baseUrl/dtm/msg/query")
        ->prepare();
    $success = $trans->submit();
    ```
- 子事务屏障

    ```
    class UserDatabase implements IDatabase
    {

      public function execute(string $query) {
          // TODO: Implement execute() method.
      }

      public function query(string $query): bool {
          // TODO: Implement query() method.
      }

      public function rollback() {
          // TODO: Implement rollback() method.
      }

      public function commit() {
          // TODO: Implement commit() method.
      }

      public function beginTrans(){

     }
    }

    $baseUrl = "http://127.0.0.1:18310";
    try {
        $trans    = new BarrierTrans([
        "trans_type" => "tcc",
        "gid"        => "ac130059_4pQHea5Xtsq",
        "op"         => "prepare",
        "branch_id"  => "01"
        ]);
        $database = new UserDatabase();
        $success  = $trans->call($database, function (IDatabase $database) {
           // 使用当前数据库连接操作,保证所有操作都在一个本地事务中
           // do what you want...
           return true;
        });
        echo "transaction result {$success}";
    } catch (Exception $exception) {
        var_dump($exception->getTraceAsString());
        echo "exception with error " . $exception->getMessage();
    }
    ```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.5% 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 ~100 days

Total

4

Last Release

1318d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4e616afd31323d0e5e1270d55de007a565d67b4e7e87d6af25580fa06b7a81bc?d=identicon)[kxg3030](/maintainers/kxg3030)

---

Top Contributors

[![kxg2020](https://avatars.githubusercontent.com/u/22949288?v=4)](https://github.com/kxg2020 "kxg2020 (58 commits)")[![kxg3030](https://avatars.githubusercontent.com/u/48542529?v=4)](https://github.com/kxg3030 "kxg3030 (3 commits)")[![imlinfly](https://avatars.githubusercontent.com/u/45063822?v=4)](https://github.com/imlinfly "imlinfly (1 commits)")

### Embed Badge

![Health badge](/badges/sett-dtmcli-php/health.svg)

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

###  Alternatives

[shlinkio/shlink

A self-hosted and PHP-based URL shortener application with CLI and REST interfaces

4.8k4.3k](/packages/shlinkio-shlink)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)[dhlparcel/magento2-plugin

DHL Parcel plugin for Magento 2

11180.5k2](/packages/dhlparcel-magento2-plugin)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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