Download the PHP package weaving/php-dtm without Composer

On this page you can find all versions of the php package weaving/php-dtm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-dtm

English | 中文

DTM Logo

Stable Version Php Version dtm-client License

PHPUnit for dtm-client Total Downloads Monthly Downloads

Introduction

dtm/dtm-client is the PHP client of Distributed Transaction Manager DTM. It has supported distributed transaction patterns of TCC pattern, Saga pattern, and two-phase message pattern. In communicate protocol it has supported communicate with DTM Server through HTTP protocol or gRPC protocol. Also the client can safely run in PHP-FPM and Swoole coroutine environment, and it has also make support more easier for Hyperf framework.

About DTM

DTM is an open source distributed transaction manager based on Go language, which provides the powerful function of combining transactions across languages and storage engines. DTM elegantly solves distributed transaction problems such as interface idempotent, null compensation, and transaction suspension, and also provides a distributed transaction solutions that are easy to use, high performance, and easy to scale horizontally.

Advantage

Comparison

In non-Java languages, there is still no mature distributed transaction manager other than DTM, so here is a comparison between DTM and Seata, the most mature open source project in Java:

Features DTM SEATA Memo
language supports Go、C#、Java、Python、PHP... Java DTM is easier implemented the client to a new language
Storage Engine Support Database, Redis, Mongo, etc. Database
Exception Handle Sub-transaction barrier is handled automatically By manual DTM solves transaction suspension, null compensation, interface idempotent etc.
SAGA Easy to use Complex state machine
Two-phase message Minimal Message Eventual Consistency Architecture
TCC
XA
AT XA is more recommended AT is similar to XA, but with dirty rollback
Single service with multiple data sources
Communicate protocol HTTP、gRPC Dubbo etc. DTM is more friendly to cloud native
Github Stargazers github stars github stars DTM released version 0.1 from 2021-06-04, developing rapidly

From the characteristics of the comparison above, DTM has great advantages in many aspects. If you consider multi-language support and multi-storage engine support, then DTM is undoubtedly your first choice.

Installation

It is very convenient to install dtm-client through Composer

Configuration

Configuration file

If you are using the Hyperf framework, after installing the component, you can publish a configuration file to ./config/autoload/dtm.php with the following vendor:publish command

If you are using a non-Hyperf framework, copy the ./vendor/dtm/dtm-client/publish/dtm.php file to the corresponding configuration directory.

Configure middleware

Before using it, you need to configure the DtmClient\Middleware\DtmMiddleware middleware as the server's global middleware. This middleware supports the PSR-15 specification and is applicable to all frameworks that support this specification. For middleware configuration in Hyperf, please refer to Hyperf Documentation - Middleware chapter.

Usage

The usage of dtm-client is very simple, we provide a sample project dtm-php/dtm-sample to help you better understand and debug. Before using this component, it is also strongly recommended that you read the DTM official documentation for a more detailed understanding.

TCC pattern

The TCC pattern is a very popular flexible distributed transaction solution. The concept of TCC is composed of the acronyms of the three words Try-Confirm-Cancel. It was first published in a paper named Life beyond Distributed Transactions:an Apostate’s Opinion by Pat Helland in 2007.

Three stages of TCC

Try phase: try to execute, complete all business checks (consistency), reserve necessary business resources (pre-isolation) Confirm stage: If all branches of the Try are successful, go to the Confirm stage. Confirm actually executes the business without any business check, and only uses the business resources reserved in the Try phase Cancel stage: If one of the Try of all branches fails, go to the Cancel stage. Releases the business resources reserved in the Try phase.

If we want to carry out a business similar to inter-bank transfer between banks, the transfer out (TransOut) and the transfer in (TransIn) are in different microservices, and a typical sequence diagram of a successfully completed TCC transaction is as follows:

Example

The following shows how to use it in the Hyperf framework, other frameworks are similar

Saga pattern

The Saga pattern is one of the most well-known solutions in the field of distributed transactions, and it is also very popular in major systems. It first appeared in the paper SAGAS published by Hector Garcaa-Molrna & Kenneth Salem in 1987.

Saga is an eventual consistency transaction, also a flexible transaction, also known as a long-running transaction . Saga is composed of a series of local transactions. After each local transaction updates the database, it will publish a message or an event to trigger the execution of the next local transaction in the Saga global transaction. If a local transaction fails because some business rules cannot be satisfied, Saga performs compensating actions for all transactions that were successfully committed before the failed transaction. Therefore, when the Saga pattern is compared with the TCC pattern, it often becomes more troublesome to implement the rollback logic due to the lack of resource reservation steps.

Sub-transaction split of Saga

For example, we want to carry out a business similar to inter-bank transfer between banks, and transfer 30 dollar in account A to account B. According to the principle of Saga transaction, we will split the entire global transaction into the following services:

The logic of the entire transaction is:

Execute the transfer out successfully => Execute the transfer in successfully => the global transaction is completed

If an error occurs in the middle, such as an error in transferring to the B account, the compensation operation of the executed branch will be called, namely:

Execute transfer out successfully => execute transfer in failure => execute transfer in compensation successfully => execute transfer out compensation successfully => global transaction rollback completed

The following is a typical sequence diagram of a successfully completed SAGA transaction:

Example

The following shows how to use it in the Hyperf framework, other frameworks are similar


All versions of php-dtm with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
ext-json Version *
hyperf/context Version ^2.2
hyperf/guzzle Version ^2.2
psr/http-server-middleware Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package weaving/php-dtm contains the following files

Loading the files please wait ....