PHP code example of fxj / swoole_server

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

    

fxj / swoole_server example snippets


/**
 * 初始化
 * TmSwoolerServer constructor.
 * @param string $host  IP/域名
 * @param int $port  端口
 * @param string $server_type 服务器类型tcp/udp/websocket
 * @param string $model 运行模式 process|base
 */
$client = new \Server\TmSwoolerServer('127.0.0.1',9502,'websocket');

//设置参数
$client->setOption(array(
    'reactor_num' => 2,
    'worker_num' => 4,
    'backlog' => 128,
    'max_request' => 50,
    'dispatch_mode' => 1,
));
//设置回调
$client->callback(\Server\Callback\SwooleWebsocketCallback::class);
//启动
$client->ServerStart();