PHPackages                             lifetime/swoole-server - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. lifetime/swoole-server

ActiveLibrary

lifetime/swoole-server
======================

a simple encapsulation of Swoole services

1.3.7(4y ago)095PHPPHP &gt;=7.1

Since Jun 28Pushed 4y ago1 watchersCompare

[ Source](https://github.com/LifeTimeNine/swoole-server)[ Packagist](https://packagist.org/packages/lifetime/swoole-server)[ RSS](/packages/lifetime-swoole-server/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (15)Used By (0)

Swoole 服务器
----------

[](#swoole-服务器)

swoole-server 对swoole的各类服务器进行一个简单的封装，让使用的时候更加方便。

已对以下服务器进行封装

- TCP/UDP
- HTTP
- WebSocket
- MQTT

### 配置类 `\swoole\Config`

[](#配置类-swooleconfig)

`\swoole\Config` 包含swoole服务器的所有配置项，详情参考 [配置](https://wiki.swoole.com/#/server/setting)

**`\swoole\Config` 类有三种使用方法**
第一种：

```
$config = new \swoole\Config([
    'host' => '0.0.0.0',
    'port' => 9501,
    'mode' => Options::MODE_PROCESS,
    'sock_type' => Options::SOCK_TYPE_TCP,
]);
$config->setConfig([
  'worker_num' => 1
]);
```

第二种：

```
$config = new \swoole\Config();
$config->setHost('0.0.0.0')
    ->setPort(9501)
    ->setMode(Options::MODE_PROCESS);
```

第三种：

```
