Home>Article>Backend Development> How to develop seata-php? Brief analysis of development guide

How to develop seata-php? Brief analysis of development guide

青灯夜游
青灯夜游 forward
2022-09-26 20:12:06 4074browse

How to develop seata-php? This article will talk about the seata-php development guide and explain some pre-requisite knowledge. I hope it will be helpful to you!

How to develop seata-php? Brief analysis of development guide

This article mainly hopes to help everyone participate in the development ofseata/seata-php, and provide some explanations of pre-requisite knowledge .

seata/seata-phpis currently a distributed transaction component package developed based on thehyperfframework and is compatible withswooleandswowTwo coroutine extensions, I hope that subsequent developers can also consider compatibility with these two coroutine extensions

Pre-requisite knowledge

I hope that everyone must understand the following things before participating inseata/seata-phpdevelopment

  • seata

  • ##hyperf development documentation

  • ##swoole documentation
  • swow
##How to start the project

First We need to find a file directory to download the code
# 根据自己实际情况来创建目录 mkdir ./seata-dev
Next enter our directory

# 根据自己实际情况来创建目录 cd ./seata-dev

We will clone seata/seata-php

# 根据自己实际情况来创建目录 git clone git@github.com:seata/seata-php.git

Next Depending on whether you are using swoole or swow, execute the following commands to create a framework project, along with a hyperf project creation document hyperf

# swoole composer create-project hyperf/hyperf-skeleton # swow composer create-project hyperf/swow-skeleton # 使用 swow 扩展建议使用 hyperf3.0 版本 composer create-project hyperf/swow-skeleton:dev-master

The next step is to enter the project and download the

clone

The

seata/seata-php

is loaded into the projectFirst we need to modify thecomposer.jsonfile in the project and add the following content

{ "require": { "hyperf/seata": "dev-master" }, "repositories": { "seata": { "type": "path", "url": "../seata-php" } } }

Finally, executecomposer update -oin the directory and project directory.

And use the commandphp bin/hyperf.php vendor:publis hyperf/seataPublish the seata configuration file

Finally usephp bin/hyperf.php startStart the project

Finally, interested friends can also learn more abouthyperfDocuments related to component package development

Component Development Guide
  • ConfigProvider Mechanism
seata -When was php started?

Finally, let me explain to you how theseata/seata-php

project was started

We can take a look at the code link ofHyperf\Seata\Listener\InitListener

in the
seata/seata-php

project:InitListener

<?php declare(strict_types=1); /** * This file is part of Hyperf. * * @link https://www.hyperf.io * @document https://hyperf.wiki * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LIC */ namespace Hyperf\Seata\Listener; use Hyperf\DbConnection\Db; use Hyperf\Event\Contract\ListenerInterface; use Hyperf\Framework\Event\MainWorkerStart; use Hyperf\Seata\Annotation\GlobalTransactionScanner; use Hyperf\Seata\Rm\DataSource\DataSourceProxy; use Hyperf\Server\Event\MainCoroutineServerStart; class InitListener implements ListenerInterface { protected GlobalTransactionScanner $globalTransactionScanner; protected DataSourceProxy $dataSourceProxy; public function __construct(GlobalTransactionScanner $globalTransactionScanner, DataSourceProxy $dataSourceProxy) { $this->globalTransactionScanner = $globalTransactionScanner; $this->dataSourceProxy = $dataSourceProxy; } public function listen(): array { // 我们这里监听了下面两个事件,在 server 启动时候,则开始执行该监听器 return [ MainCoroutineServerStart::class, MainWorkerStart::class, ]; } public function process(object $event) { // Execute any sql to init the database connection Db::select('select 1'); // Init TM and RM clients // 这里则是开始初始化 TM 和 RM 的客户端 $this->globalTransactionScanner->initClients(); } }
At the end Let’s take a look at the life cycle document ofhyperf

hyperf-life cycle event

Recommended study: "PHP Video Tutorial"

The above is the detailed content of How to develop seata-php? Brief analysis of development guide. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete