Introduction to imi
imi is a distributed PHP development framework that supports long-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
about the author
Yurun (Zhang Runyu), member of Swoole development team , php-src kernel contributor , TDengine contributor , top 100 in 2021 China Open Source Code Power List
Progress Description (20220709)
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.
And based on Nacos developed an imi-nacos to implement configuration center components.
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
It is under development and may be modified at any time, please do not use it in production environment! (But you are also welcome to try new things and make suggestions)
When developing imi-nacos, because the existing PHP Nacos components have various problems, I developed one myself: nacos-php
During the development of nacos-php, I found some problems in the Nacos document (in fact, it may be a design and specification problem), and I helped them improve the document: https://github.com/nacos-group/nacos-group.github. io/pull/290
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, we 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.
Use of imi-nacos
Install
composer require imiphp/imi-nacos
Instructions for use
configure
@app.beans
:
[
'ConfigCenter' => [
// 'mode' => \Imi\ConfigCenter\Enum\Mode::WORKER, // 工作进程模式
'mode' => \Imi\ConfigCenter\Enum\Mode::PROCESS, // 进程模式
'configs' => [
'nacos' => [
'driver' => \Imi\Nacos\Config\NacosConfigDriver::class,
// 客户端连接配置
'client' => [
'host' => '127.0.0.1', // 主机名
'port' => 8848, // 端口号
'prefix' => '/', // 前缀
'username' => 'nacos', // 用户名
'password' => 'nacos', // 密码
'timeout' => 60000, // 网络请求超时时间,单位:毫秒
'ssl' => false, // 是否使用 ssl(https) 请求
'authorizationBearer' => false, // 是否使用请求头 Authorization: Bearer {accessToken} 方式传递 Token,旧版本 Nacos 需要设为 true
],
// 监听器配置
'listener' => [
'timeout' => 30000, // 配置监听器长轮询超时时间,单位:毫秒
'failedWaitTime' => 3000, // 失败后等待重试时间,单位:毫秒
'savePath' => Imi::getRuntimePath('config-cache'), // 配置保存路径,默认为空不保存到文件。php-fpm 模式请一定要设置!
'fileCacheTime' => 30, // 文件缓存时间,默认为0时不受缓存影响,此配置只影响 pull 操作。php-fpm 模式请一定要设置为大于0的值!
'pollingInterval' => 10000, // 客户端轮询间隔时间,单位:毫秒
],
// 配置项
'configs' => [
'nacos' => [
'key' => 'imi-nacos-key1',
'group' => 'imi',
],
],
],
],
],
]
get configuration
\Imi\Config::get('nacos'); // 对应 imi-nacos-key1
write configuration
/** @var \Imi\ConfigCenter\ConfigCenter $configCenter */
$configCenter = App::getBean('ConfigCenter');
$name = 'imi-nacos-key1';
$group = 'imi';
$type = 'json';
$value = json_encode(['imi' => 'niubi']);
$configCenter->getDriver('nacos')->push($name, $value, [
'group' => $group,
'type' => $type,
]);
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, etcd, 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.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。