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

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

青灯夜游
Release: 2023-04-11 07:58:01
forward
4199 people have browsed it

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 of seata/seata-php, and provide some explanations of pre-requisite knowledge .

seata/seata-php is currently a distributed transaction component package developed based on the hyperf framework and is compatible with swoole and swow Two 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 in seata/seata-php development

  • 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
Copy after login
Next enter our directory

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

We will clone seata/seata-php

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

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
Copy after login

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 the composer.json file in the project and add the following content

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

Finally, execute composer update -o in the directory and project directory.

And use the command php bin/hyperf.php vendor:publis hyperf/seata Publish the seata configuration file

Finally use php bin/hyperf.php start Start the project

Finally, interested friends can also learn more about hyperf Documents related to component package development

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

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

project was started

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

in the
seata/seata-php

project:InitListener<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">&lt;?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-&gt;globalTransactionScanner = $globalTransactionScanner;         $this-&gt;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-&gt;globalTransactionScanner-&gt;initClients();     } }</pre><div class="contentsignin">Copy after login</div></div>At the end Let’s take a look at the life cycle document of hyperf

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!

Related labels:
php
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template