swoole 的 Yii扩展,支持 tcp,websocket,定时器,udp [ 1.0 版本 ]
yii2 swoole extension
在swoole环境下运行Yii2应用。
yii2-swoole基于Yii2组件化进行编程,对业务和Yii2无侵入性。
快速开始
初始化Yii2应用
安装扩展
composer require yii-diandi/yii2-swoole
websocket配置文件
<?php
/**
* @Author: Wang chunsheng email:2192138785@qq.com
* @Date: 2021-01-19 20:27:15
* @Last Modified by: Wang chunsheng email:2192138785@qq.com
* @Last Modified time: 2021-01-20 04:14:02
*/
return [
'host' => '0.0.0.0',
'port' => 9502,
'mode' => SWOOLE_PROCESS,
'sockType' => SWOOLE_SOCK_TCP,
'type'=>'ws',
'app' => require __DIR__ . '/web.php',
'options' => [
'pid_file' => __DIR__ . '/../runtime/websocket.pid',
'log_file' => __DIR__ . '/../runtime/websocket.log',
'debug_mode'=> 1,
'user'=>'www',
'group'=>'www',
// 4.0 新增选项
'worker_num' => 2,
'daemonize' => 0,
'task_worker_num' => 10
]
];
web服务配置
<?php
/**
* @Author: Wang chunsheng email:2192138785@qq.com
* @Date: 2021-01-19 20:27:34
* @Last Modified by: Wang chunsheng email:2192138785@qq.com
* @Last Modified time: 2021-01-20 04:24:28
*/
use diandi\swoole\web\ErrorHandler;
use diandi\swoole\web\Request;
use diandi\swoole\web\Response;
use yii\caching\FileCache;
$db = require(__DIR__ . '/../../../common/config/db.php');
return [
'id' => 'swooleService',
'name' => '店滴Swoole',
'basePath' => dirname(__DIR__),
'language' => 'zh-CN',
'bootstrap' => ['log'],
'controllerNamespace' => 'swooleService\controllers',
'taskNamespace' => 'swooleService\tasks',
'aliases' => [
'@swooleService' => dirname(__DIR__),
],
'components' => [
'response' => [
'class' => Response::class,
'format' => Response::FORMAT_JSON
],
'request' => [
'class' => Request::class,
'cookieValidationKey' => '123456'
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
]
],
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'class' => ErrorHandler::class
],
'db' => $db,
'redis' => [
'class' => 'yii\redis\Connection',
'hostname' => 'localhost',
'port' => 6379,
'database' => 2
],
'cache' => [
'class' => 'yii\redis\Cache',
],
],
'params' => require __DIR__ . '/params.php'
];
TCP服务配置
<?php
/**
* @Author: Wang chunsheng email:2192138785@qq.com
* @Date: 2021-01-19 20:27:15
* @Last Modified by: Wang chunsheng email:2192138785@qq.com
* @Last Modified time: 2021-01-21 02:47:30
*/
return [
'host' => '0.0.0.0',
'port' => 9501,
'mode' => SWOOLE_PROCESS,
'sockType' => SWOOLE_SOCK_TCP,
'app' => require __DIR__ . '/web.php',
'options' => [
'pid_file' => __DIR__ . '/../runtime/swoole.pid',
'log_file' => __DIR__ . '/../runtime/swoole.log',
'debug_mode'=> 1,
'user'=>'www',
'group'=>'www',
// 4.0 新增选项
'worker_num' => 2,
'daemonize' => 0,
'task_worker_num' => 10
]
];
店滴多商户开源框架
注册时间:2017-12-25
最后登录:2024-05-05
在线时长:26小时16分
最后登录:2024-05-05
在线时长:26小时16分
- 粉丝1
- 金钱255
- 威望30
- 积分815
共 4 条评论
http协议 支持么?
支持的,老铁
支持的,老弟,一句命令行的事情
会内存泄漏吗
需要进一步论证
最新版里面,内存泄露得到处理
老弟,内存泄露的问题需要通过连接池,协程等技术方式解决,是可以处理的
开源地址 https://gitee.com/wayfirer/diandicms