imi框架介绍
imi v2.0 长连接分布式 PHP 开发框架。
imi可以运行在 PHP-FPM、Swoole、Workerman 多种容器环境下。
Github: https://github.com/imiphp/imi
Gitee: https://gitee.com/yurunsoft/IMI
开发文档:https://doc.imiphp.com/v2.0/
运行环境
[root@iZbp1ff38278eoy1t5paezZ ~]# php -v
PHP 7.4.21 (cli) (built: Jul 13 2021 10:47:02) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
[root@iZbp1ff38278eoy1t5paezZ ~]# composer -V
Composer version 2.1.14 2021-11-30 10:51:43
[root@iZbp1ff38278eoy1t5paezZ ~]# php -m
[PHP Modules]
...
PDO
pdo_mysql
pdo_sqlite
Phar
posix
redis
sqlite3
standard
swoole
...
[Zend Modules]
开始一个新项目
创建 Http Server 项目:composer create-project imiphp/project-http:~2.0.0
创建 WebSocket Server 项目:composer create-project imiphp/project-websocket:~2.0.0
创建 TCP Server 项目:composer create-project imiphp/project-tcp:~2.0.0
创建 UDP Server 项目:composer create-project imiphp/project-udp:~2.0.0
创建 MQTT Server 项目:composer create-project imiphp/project-mqtt:~2.0.0
引入Swoole组件
默认没有引入 Swoole 组件,如有需要请手动引入:composer require imiphp/imi-swoole:~2.0.0 ,否则无法以 Swoole 模式运行
启动命令
PHP-FPM模式:
vendor/bin/imi-cli fpm/start
// 20220327203521
// http://IP:8080/api
{
"mode": "fpm",
"hello": "imi",
"time": "2022-03-27 20:35:21"
}
Swoole模式:
vendor/bin/imi-swoole swoole/start
须引入swoole组件:composer require imiphp/imi-swoole:~2.0.2
// 20220327203600
// http://IP:8080/api
{
"mode": "swoole",
"hello": "imi",
"time": "2022-03-27 20:36:00"
}
Workerman模式:
vendor/bin/imi-workerman workerman/start
需要开放pcntl相关函数
// 20220327203721
// http://IP:8080/api
{
"mode": "workerman",
"hello": "imi",
"time": "2022-03-27 20:37:21"
}
切换环境运行前建议删除运行时文件目录:
rm -rf .runtime/*runtime
遇到的相关问题:Failed to listen on 0.0.0.0:8080 (reason: Address already in use),解决办法请自行百度
相关视频教程:[01]http 服务 hello world-imi 2.0基础视频教程|PHP|Swoole|Workerman
网友评论