All Projects → deepziyu → Yii2 Swoole

deepziyu / Yii2 Swoole

Licence: bsd-3-clause
full solutions making yii2-framework run on swoole with coroutine.

Projects that are alternatives of or similar to Yii2 Swoole

Php Coroutine Engine
This project for php-fpm support coroutine
Stars: ✭ 74 (-13.95%)
Mutual labels:  coroutine, swoole
Swoft Framework
[READ ONLY] Swoft Framework, base of Swoft
Stars: ✭ 70 (-18.6%)
Mutual labels:  coroutine, swoole
Yurunoauthlogin
PHP 第三方登录授权 SDK,集成了QQ、微信、微博、Github等常用接口。支持 php-fpm 和 Swoole,所有框架通用。QQ群:17916227
Stars: ✭ 330 (+283.72%)
Mutual labels:  coroutine, swoole
PHPMailer-Swoole
安装最新版Swoole,开启一键协程化,使用原版phpmailer就可以实现协程化了。本项目已经没有维护下去的意义。
Stars: ✭ 25 (-70.93%)
Mutual labels:  swoole, coroutine
Swoft Db
[READ ONLY] Database Compoment for Swoft
Stars: ✭ 25 (-70.93%)
Mutual labels:  coroutine, swoole
Simps
🚀 A simple, lightweight and high-performance PHP coroutine framework.
Stars: ✭ 318 (+269.77%)
Mutual labels:  coroutine, swoole
Easyswoole
swoole,easyswoole,swoole framework
Stars: ✭ 4,409 (+5026.74%)
Mutual labels:  coroutine, swoole
Yurunhttp
YurunHttp 是开源的 PHP HTTP 客户端,支持链式操作,简单易用。完美支持Curl、Swoole 协程。QQ群:17916227
Stars: ✭ 197 (+129.07%)
Mutual labels:  coroutine, swoole
Paysdk
PHP 集成支付 SDK ,集成了支付宝、微信支付的支付接口和其它相关接口的操作。支持 php-fpm 和 Swoole,所有框架通用。宇润PHP全家桶技术支持群:17916227
Stars: ✭ 723 (+740.7%)
Mutual labels:  coroutine, swoole
Imi
imi 是基于 Swoole 的 PHP 协程开发框架,它支持 Http、Http2、WebSocket、TCP、UDP、MQTT 等主流协议的服务开发,特别适合互联网微服务、即时通讯聊天im、物联网等场景!。QQ群:17916227
Stars: ✭ 680 (+690.7%)
Mutual labels:  coroutine, swoole
swoole-postgresql-doctrine-driver
🔌 A Doctrine DBAL Driver implementation on top of Swoole Coroutine PostgreSQL client
Stars: ✭ 15 (-82.56%)
Mutual labels:  swoole, coroutine
Ycsocket
基于swoole的socket框架,支持协程版MySQL、Redis连接池,已用于大型RPG游戏服务端
Stars: ✭ 77 (-10.47%)
Mutual labels:  coroutine, swoole
zhamao-framework
协程、高性能、灵活的聊天机器人 & Web 开发框架(炸毛框架)
Stars: ✭ 99 (+15.12%)
Mutual labels:  swoole, coroutine
Shadowfax
Run Laravel on Swoole.
Stars: ✭ 325 (+277.91%)
Mutual labels:  coroutine, swoole
ext-postgresql
🐘 Coroutine-based client for PostgreSQL
Stars: ✭ 62 (-27.91%)
Mutual labels:  swoole, coroutine
Hyperf
🚀 A coroutine framework that focuses on hyperspeed and flexibility. Building microservice or middleware with ease.
Stars: ✭ 4,206 (+4790.7%)
Mutual labels:  coroutine, swoole
Yii2 Swoole
make yii2 project runing on swoole
Stars: ✭ 161 (+87.21%)
Mutual labels:  coroutine, swoole
Hyperf Skeleton
🛠 A skeleton of Hyperf framework that provided by official team
Stars: ✭ 162 (+88.37%)
Mutual labels:  coroutine, swoole
Swoft
🚀 PHP Microservice Full Coroutine Framework
Stars: ✭ 5,420 (+6202.33%)
Mutual labels:  coroutine, swoole
Saber
⚔️ Saber, PHP异步协程HTTP客户端 | PHP Coroutine HTTP client - Swoole Humanization Library
Stars: ✭ 866 (+906.98%)
Mutual labels:  coroutine, swoole

yii2-swoole

为赋予 Yii2 框架协程异步能力而生。

后期开发会依赖 Swoft 框架 去实现功能,相信 Swoft 会是下一代优秀的框架。

此插件基于 swoole (v2.0) 底层实现的协程,改造 Yii2 的核心代码,使开发者无感知,以及在不改动业务代码的情况下,用上 swoole 的异步IO能力。

特性

  • 协程 MySQL 客户端、连接池,支持主从、事务。

  • 协程 Redis 客户端、连接池、缓存 (目前未打算支持事务)

  • 协程 HttpClient , 依赖于 Swoft 实现

  • swoole_table 缓存组件

  • 异步文件日志组件

  • 业务代码和 swoole 主进程分离

安装

环境要求

  1. hiredis
  2. composer
  3. PHP7.X
  4. Swoole2.1 且开启协程和异步 Redis

swoole install

composer install

  • 在项目中的 composer.json 文件中添加依赖:
{
  "require": {
      "deepziyu/yii2-swoole": "*"
  }
}
  • 执行 $ php composer.phar update$ composer update 进行安装。

配置

你可以参考 这个示例项目

新建一个启动文件即可。

启动文件清晰的展现出本插件的工作、流程原理。动手写这个文件有助于你更加理解本插件。

swoole.php 示例如下:

defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
defined('WEB_ROOT') or define('WEB_ROOT', dirname(__DIR__) . '/web'); //web目录的路径,用户访问的静态文件都放这里

require(__DIR__ . '/../../vendor/autoload.php');

$config = [
    'id' => 'api-test-hello',
    'setting' => [
        // swoole_server 的配置。
        // @see 其他配置项见 https://wiki.swoole.com/wiki/page/274.html
        'daemonize'=>0,
        'worker_num'=>2,
        'task_worker_num' => 1,
        'log_file' => __DIR__.'/../runtime/logs/swoole.log',
        'log_level'=> 0,
        'chroot' => '/',
    ],
    'cacheTable' => function (){
        // swoole_table 需要提前启动,大小为 2 的次方
        return deepziyu\yii\swoole\cache\SwooleCache::initCacheTable(1024);
    },
    'bootstrap' => [
        'class' => 'deepziyu\yii\swoole\bootstrap\YiiWeb',
        'config' => function(){
            // 用闭包是为了延迟加载
            // 返回 Yii 的各个组件的配置
            require_once(__DIR__ . '/../../vendor/autoload.php');
            require_once(__DIR__ . '/../../yii-swoole/Yii.php');
            require(__DIR__ . '/../config/bootstrap.php');

            $config = yii\helpers\ArrayHelper::merge(
                require(__DIR__ . '/../config/main.php'),
                require(__DIR__ . '/../config/main-local.php'),
                [
                    'components' => [
                      'errorHandler' => [
                           'class'=>'deepziyu\yii\swoole\web\ErrorHandler'
                        ],
                        'cache' => [
                            'class' => 'deepziyu\yii\swoole\cache\SwooleCache',
                        ],
                    ],
                ]
            );

            return $config;
        },
    ],

];

// 配置了这么多,最终还是逃不过一 run()
deepziyu\yii\swoole\server\Server::run($config);

启动

php swoole.php start|stop|reload|reload-task

Usage HttpClient

HTTP 客户端的使用请参考 Swotf 文档

TODO

  • MysqlPool 目前不支持事务 (transaction)。 ( 已实现 )
  • MysqlPool、RedisPool 连接池用满了,目前是用 sleep() 进行排队等待,超过等待次数后,报异常。
  • MysqlPool 目前不支持主从。 ( 已实现 )

已知Bug

  • 迭代器将导致协程挂起。

    BUG代码:

        $models = User::find()->each(10);
        foreach ($models as $model) { // Hang up in this row
             $data[] = $model->toArray();
        }
    

已解决Bug

  • new ActiveRecord([]); 中会触发 __set() 魔术方法中调用协程Client,导致两个问题:

    1、 首次实例化会导致协程挂起。

    2、 如果 SQL 报错直接导致 work 进程终止。

    BUG代码:

        class OneModel extend ActiveRecord{
            public static function tableName()
            {
               return 'some-table do not exist';
            }
        }
        //导致进程终止
        $model = new OneModel([
            'some-att'=>'some-value',
        ]);
    

链接

gitee 仓库

github 仓库

Chat && Help

Swoft 框架QQ交流群:548173319

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].