1. Go to this page and download the library: Download nobody/yii2-swoole library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nobody / yii2-swoole example snippets
composer
use \nobody\swoole\server\Server;
//站点根目录,相当于nginx的root配置
defined('WEBROOT') or define('WEBROOT', __DIR__);
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
//协程与非协程的切换
defined('COROUTINE_ENV') or define('COROUTINE_ENV', true);
',
'log_file' => __DIR__.'/../runtime/logs/swoole.log',
'debug_mode'=> 1,
'user'=>'tsingsun',
'group'=>'staff',
],
];
Server::run($config,function (Server $server){
$starter = new \nobody\swoole\bootstrap\WebApp($server);
//初始化函数独立,为了在启动时,不会加载Yii相关的文件,在库更新时采用reload平滑启动服务器
$starter->init = function (\nobody\swoole\bootstrap\BaseBootstrap $bootstrap) {
//需要使用Yii-Swoole项目的Yii文件,