PHP code example of xiaochengfu / yii2-swoole

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

    

xiaochengfu / yii2-swoole example snippets


return [
    'swooleAsync' => [
        'host'             => 'ip', 		//服务启动IP
        'port'             => '9512',      		//服务启动端口
        'swoole_http'      => 'http://ip:9512',//推送触发连接地址
        'process_name'     => 'swooleWebSocket',		//服务进程名
        'open_tcp_nodelay' => '1',         		//启用open_tcp_nodelay
        'daemonize'        => false,				//守护进程化
        'heartbeat_idle_time' => 180,               //客户端向服务端请求的间隔时间,单位秒(s)
        'heartbeat_check_interval' => 120,          //服务端向客户端发送心跳包的间隔时间,两参数要配合使用,单位秒(s)
        'worker_num'       => '2',				//work进程数目
        'task_worker_num'  => '2',				//task进程的数量
        'task_max_request' => '10000',			//work进程最大处理的请求数
        'pidfile'           => Yii::getAlias('@swoole').'/yii2-swoole/yii2-swoole.pid',
        'log_dir'           => Yii::getAlias('@swoole').'/yii2-swoole',
        'task_tmpdir'       => Yii::getAlias('@swoole').'/yii2-swoole',
        'log_file'          => Yii::getAlias('@swoole').'/yii2-swoole/swoole.log',
        'log_size'          => 204800000,       //运行时日志 单个文件大小
    ]
];

 'controllerMap' => [
        'swoole' => [
            'class' => 'xiaochengfu\swoole\console\SwooleController',
        ],
        //test主要用来测试
        'test' => [
            'class' => 'xiaochengfu\swoole\console\TestController',
        ],
    ],

'components' => [
     'swoole' => [
                 'class' => 'xiaochengfu\swoole\component\SwooleAsyncComponent',
             ]
]

Yii::$app->swoole->pushMsg($fd,$data);

Yii::setAlias('@swoole',dirname(dirname(__DIR__)) . '/swoolelog');

php /path/to/yii/application/yii test cli