PHP code example of tsingsun / yii2-swoole

1. Go to this page and download the library: Download tsingsun/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/ */

    

tsingsun / yii2-swoole example snippets


    composer 

use \tsingsun\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);

e' => __DIR__.'/../runtime/logs/swoole.log',
        'debug_mode'=> 1,
        'user'=>'tsingsun',
        'group'=>'staff',
        // 4.0 新增选项
        'enable_coroutine' => COROUTINE_ENV
    ],
];

Server::run($config,function (Server $server){
    $starter = new \tsingsun\swoole\bootstrap\WebApp($server);
    //初始化函数独立,为了在启动时,不会加载Yii相关的文件,在库更新时采用reload平滑启动服务器
    $starter->init = function (\tsingsun\swoole\bootstrap\BaseBootstrap $bootstrap) {
        //需要使用Yii-Swoole项目的Yii文件,
        

//启动
php http_server.php start
//平滑重启,kill方式,需要root权限, 
php http_server.php reload
//关闭
php http_server.php stop