Progress Description (20220902)
imi-zookeeper currently implements the function of configuration center. Since imi-config-center abstracts the interface, it is very similar to imi-nacos and imi-etcd in use.
At the same time, the work of accessing the microservice registry for imi has begun. The first registry to be accessed is Nacos.
At present, the service registration with Nacos has been realized, and the next work is to realize the service call through the registration center.
When implementing imi-zookeeper, two extensions are used, namely php-zookeeper and swoole-zookeeper. During the test, some problems in the extension were found, and they were fixed.
The PR of swoole-zookeeper has been merged: https://github.com/swoole/ext-zookeeper/pull/44
The PR of php-zookeeper has not been merged as of press time: https://github.com/php-zookeeper/php-zookeeper/pull/53
When developing open source projects, other open source projects are used, and problems are found to help solve them. This is true open source.
I personally and imi welcome everyone to participate in open source, and joint construction can make the project develop better and better.
Yurun introduced the next development plan to everyone at the imi's fourth anniversary live event.
Among them, it is clearly pointed out that the imi development team should vigorously develop the microservice ecosystem and contribute to PHP microservices.
The first step is to configure the center for imi access.
At present, the abstraction of the imi-config-center configuration center component has been implemented.
Implemented and released v2.1.0-beta
version:
All have been written and passed automated integration tests, and test cases are the basic requirements of the imi development team for imi-related development
Use of imi-zookeeper
Install
- Swoole users please install the swoole-zookeeper extension.
- Non-Swoole users please install the php-zookeeper extension.
composer require imiphp/imi-zookeeper:~2.1.0
Instructions for use
configure
@app.beans
:
[
'ConfigCenter' => [
// 'mode' => \Imi\ConfigCenter\Enum\Mode::WORKER, // 工作进程模式
'mode' => \Imi\ConfigCenter\Enum\Mode::PROCESS, // 进程模式
'configs' => [
'zookeeper' => [
'driver' => \Imi\ZooKeeper\Config\SwooleZooKeeperConfigDriver::class, // Swoole 驱动
// 'driver' => \Imi\ZooKeeper\Config\ZooKeeperConfigDriver::class, // 非 Swoole 驱动
// 客户端连接配置
'client' => [
'host' => env('IMI_ZOOKEEPER_HOST', '127.0.0.1:2181'), // 主机名:端口
'timeout' => 10, // 网络请求超时时间,单位:秒
],
// 监听器配置
'listener' => [
'timeout' => 30000, // 配置监听器长轮询超时时间,单位:毫秒
'failedWaitTime' => 3000, // 失败后等待重试时间,单位:毫秒
'savePath' => Imi::getRuntimePath('config-cache'), // 配置保存路径,默认为空不保存到文件。php-fpm 模式请一定要设置!
'fileCacheTime' => 30, // 文件缓存时间,默认为0时不受缓存影响,此配置只影响 pull 操作。php-fpm 模式请一定要设置为大于0的值!
'pollingInterval' => 10000, // 客户端轮询间隔时间,单位:毫秒
],
// 配置项
'configs' => [
'zookeeper' => [
'key' => 'imi-zooKeeper-key1',
'type' => 'json', // 配置内容类型
],
],
],
],
],
]
get configuration
\Imi\Config::get('zookeeper'); // 对应 imi-zooKeeper-key1
write configuration
/** @var \Imi\ConfigCenter\ConfigCenter $configCenter */
$configCenter = App::getBean('ConfigCenter');
$name = 'imi-zooKeeper-key1';
$value = json_encode(['imi' => 'niubi']);
$configCenter->getDriver('zookeeper')->push($name, $value);
Benefits of Configuration Center
We usually put some configuration into a special configuration file, which is usually distributed and deployed with the code.
When you need to modify the configuration, you need to go through the release process again, which is very cumbersome and inconvenient.
At this time, the role of the configuration center is reflected.
We take the configuration from the configuration center instead of writing it in the project, and can flexibly realize the configuration release without interrupting the service.
imi configuration center component design
monitor mode
Worker Process Mode
Each process monitors itself, which is suitable for the Swoole environment.
Process mode
Monitored by a dedicated process and notified to other processes. Applicable to Swoole, Workerman environment.
Less pressure on the configuration center.
The php-fpm mode is special, it is the file caching logic. It takes more than a certain time to request the configuration center to obtain data, and the real-time performance will have a certain impact.
Monitoring method
Client polling
The client regularly requests the configuration center, which puts a lot of pressure on the configuration center server, but it is the most common.
Server push (long polling)
If the configuration center supports server push (long polling), it is recommended to use this method to reduce the pressure on the configuration center server.
near-term development plan
- Continue to maintain and iterate the core functions of imi remain unchanged for thousands of years
- Develop more specific implementations of imi configuration centers (Apollo, Zookeeper, Consul)
If you are interested in open source and imi projects, you may wish to develop together.
Simply develop an approved imi component or an imi-based open source project to become a member of the imi development team.
Introduction to imi
imi is a distributed PHP development framework that supports long-term connection microservices. It can run in various container environments such as PHP-FPM, Swoole, Workerman, and RoadRunner.
imi has rich functional components, and the v2.1 version has built-in 2 solutions for distributed long-term connection services.
The imi framework is now running stably in: cultural travel e-commerce platform, IoT charging cloud platform, parking cloud platform, payment microservice, SMS microservice, wallet microservice, card game server, data migration service (Hupu), etc. in the project.
The first version of imi was published on June 21, 2018
project address
- Github: https://github.com/imiphp/imi
- Gitee: https://gitee.com/yurunsoft/IMI
- Official website: https://www.imiphp.com/
- Documentation: https://doc.imiphp.com/v2.1/
Honors received
- Recommended by InfoQ: https://mp.weixin.qq.com/s/oBbPRE0fvJR7aKOzJM_wxQ
- Code Cloud GVP Project: https://gitee.com/yurunsoft/IMI
Development team members
Yurun (Zhang Runyu), born on Arbor Day in 1994, is a native of Wuxi. Swoole development team member , php-src kernel contributor , TDengine contributor , top 100 Chinese open source code list in 2021 .
Open source projects include but are not limited to: imi, PaySDK, YurunHttp, Guzzle-Swoole, YurunOAuthLogin, ChineseUtil, etc.
Github: https://github.com/Yurunsoft
NHZEX, main contributions: code optimization, bug fixes, test optimization, PHP 8.1 compatibility
Github: https://github.com/NHZEX
Fengchen, 1993, Leo, native of Xuancheng. Member of the imi framework development team, open source author.
Open source projects include but are not limited to: fcup, mjs, university font icon library, fcphp, fcblog, etc. Major contributions: early users of imi, authors of imi 1.0 and 2.0 official website pages
Github: https://github.com/lovefc
Arno Eno, born in 1999, a native of Chengdu, full-stack programmer (main backend), medical student (undergraduate nursing major), master candidate of World War II.
Common programming languages PHP, NodeJs, etc., member of the imi framework development team.
A nurse who is keen to create the world with code. He loves PHP only. He has led the development of more than 20 WEB projects mainly using PHP as the backend during college. .
Major contributions: documentation, bug fixes
Github: https://github.com/Gumo666
Qingxuan Chris, 1996, Cantonese, PHP trainee for n and a half years, likes to sing\dance\RAP\PHP, member of the imi framework development team
Likes to participate in open source power generation with love, member of the imi framework development team, and contributor to the EasySwoole community
Main contribution: imi-etcd author
Github: https://github.com/ChrisLeeAreemm
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。