Home>Article>Backend Development> How to develop seata-php? Brief analysis of development guide
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!
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 thehyperf
framework and is compatible withswoole
andswow
Two coroutine extensions, I hope that subsequent developers can also consider compatibility with these two coroutine extensions
I hope that everyone must understand the following things before participating inseata/seata-phpdevelopment
##How to start the project# 根据自己实际情况来创建目录 mkdir ./seata-devNext 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
cloneThe
seata/seata-phpis 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" } } }
Finally, executecomposer update -o
in the directory and project directory.
And use the commandphp bin/hyperf.php vendor:publis hyperf/seata
Publish the seata configuration file
Finally usephp bin/hyperf.php start
Start the project
Finally, interested friends can also learn more abouthyperf
Documents related to component package development
seata/seata-phpin the
We can take a look at the code link of
Hyperf\Seata\Listener\InitListener
project:InitListener
At the end Let’s take a look at the life cycle document ofhyperf<?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(); } }
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!