swoole-foundation/yii2-swoole-extension
Composer 安装命令:
composer require swoole-foundation/yii2-swoole-extension
包简介
running yii2 web application on swoole server
README 文档
README
Running Yii2 application on Swoole Environment.
This extension based on Component-Driven development.
There is no side effects to your business or Yii2 framework.
Get Started
-
Initialize your Yii application
composer create-project --prefer-dist yiisoft/yii2-app-basic basic
-
Install this package by composer
composer require swoole-foundation/yii2-swoole-extension
-
Create server configuration file.
// config/server.php <?php return [ 'host' => 'localhost', 'port' => 9501, 'mode' => SWOOLE_PROCESS, 'sockType' => SWOOLE_SOCK_TCP, 'app' => require __DIR__ . '/swoole.php', 'options' => [ // options for swoole server 'pid_file' => __DIR__ . '/../runtime/swoole.pid', 'worker_num' => 2, 'daemonize' => 0, 'task_worker_num' => 2, ] ];
-
Create swoole.php and replace the default web components of Yii2。
Thanks for @RicardoSette
// config/swoole.php <?php $config = require __DIR__ . '/web.php'; $config['components']['response']['class'] = swoole\foundation\web\Response::class; $config['components']['request']['class'] = swoole\foundation\web\Request::class; $config['components']['errorHandler']['class'] = swoole\foundation\web\ErrorHandler::class; return $config;
-
Create bootstrap file.
// bootstrap.php <?php /** * @author xialeistudio * @date 2019-05-17 */ use swoole\foundation\web\Server; use Swoole\Runtime; // Warning: singleton in coroutine environment is untested! Runtime::enableCoroutine(); defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_ENV') or define('YII_ENV', getenv('PHP_ENV') === 'development' ? 'dev' : 'prod'); require __DIR__ . '/vendor/autoload.php'; require __DIR__ . '/vendor/yiisoft/yii2/Yii.php'; // require your server configuration $config = require __DIR__ . '/config/server.php'; // construct a server instance $server = new Server($config); // start the swoole server $server->start();
- Start your app.
php bootstrap.php
- Congratulations! Your first Yii2 Swoole Application is running!
Examples
Theres is an complete application in tests directory.
Todo
- Fix coroutine environment
- Support for docker
- Add test case
- Work with travis-ci
Contribution
This Project only works because of contributions by users like you!
- Fork this project
- Create your branch
- Make a pull request
- Wait for merge
swoole-foundation/yii2-swoole-extension 适用场景与选型建议
swoole-foundation/yii2-swoole-extension 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.78k 次下载、GitHub Stars 达 43, 最近一次更新时间为 2019 年 05 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「yii2」 「swoole」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 swoole-foundation/yii2-swoole-extension 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 swoole-foundation/yii2-swoole-extension 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 swoole-foundation/yii2-swoole-extension 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A custom URL rule class for Yii 2 which allows to create translated URL rules
annotations-scan-plugin
SCEditor, a lightweight WYSIWYG BBCode & HTML editor extension for Yii 2.0 Framework
SForum
think-orm协程化版本, 仅在swoole协程环境使用
Redirect all not authenticated web user to login page.
统计信息
- 总下载量: 12.78k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 43
- 点击次数: 8
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-05-17