# Config

### Config Fields

| Name          | Type   | Explanation                                     | Example                                        |
| ------------- | ------ | ----------------------------------------------- | ---------------------------------------------- |
| router        | obj    | Router(Request Method、Path、Handler、Middlewares) | See below                                      |
| server        | obj    | Swoole Server Config                            | See below                                      |
| redis         | obj    | Redis Config                                    | See below                                      |
| mysql         | obj    | MySQL Config                                    | See below                                      |
| log           | obj    | Log Config                                      | See below                                      |
| elasticsearch | obj    | Elasticsearch Config                            | See below                                      |
| middleware    | array  | Global Middlewares                              | \[\App\middlewares\Cors::class]                |
| cors          | obj    | Cross Domain Config                             | See below                                      |
| storage       | obj    | Storage System Config                           | See below                                      |
| timezone      | string | Default Timezone                                | \App\components\Helper::env('TIMEZONE', 'PRC') |
| monitor       | obj    | Runtime Monitor Config                          | See below                                      |
| amqp          | obj    | AMQP Protocol Config                            | See below                                      |
| events        | obj    | Events & Listeners                              | Please see [Events](../other-1/events)         |

### Router Config

| Name   | Type  | Explanation                                     | Example                                                                                           |
| ------ | ----- | ----------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| single | array | Router(Request Method、Path、Handler、Middlewares) | \['GET', '/redis', \[\App\services\DemoService::class, 'redis', \[\App\middlewares\Cors::class]]] |
| group  | obj   | Group Router                                    | Please see [Router](../mvc/router)                                                                |

### Swoole Server Config

For detailed explanation, please see [document](https://wiki.swoole.com/wiki/page/274.html).

| Name           | Type   | Explanation                  | Example   |
| -------------- | ------ | ---------------------------- | --------- |
| host           | string | Swoole Listening Host        | 127.0.0.1 |
| port           | int    | Swoole Listening Port        | 9501      |
| reactor\_num   | int    | Swoole Reactor Thread Number | 8         |
| worker\_num    | int    | Swoole Worker Process Number | 32        |
| daemonize      | bool   | Swoole Daemon Mode Switch    | false     |
| backlog        | int    | TCP Backlog Size             | 128       |
| max\_request   | int    | Swoole Worker Max Request    | 0         |
| dispatch\_mode | int    | Swoole Request Dispatch Mode | 2         |

### Redis Config

| Name                 | Type   | Explanation                               | Example     |
| -------------------- | ------ | ----------------------------------------- | ----------- |
| host                 | string | Redis Server Host                         | 127.0.0.1   |
| port                 | int    | Redis Server Port                         | 6379        |
| timeout              | double | Redis Connection Timeout                  | 1           |
| pool\_size           | int    | Redis Connection Pool Size                | 5           |
| passwd               | string | Redis Auth Password                       | null        |
| db                   | int    | Redis DB Index                            | 0           |
| switch               | int    | Redis Component Switch                    | 0           |
| prefix               | string | Redis Key Prefix                          | sw-fw-less: |
| pool\_change\_event  | int    | Redis Pool Change Event                   | 0           |
| report\_pool\_change | int    | Whether to report redis pool change event | 0           |

### MySQL Config

| Name                 | Type   | Explanation | Example |
| -------------------- | ------ | ----------- | ------- |
| dsn                  | string |             |         |
| username             | string |             |         |
| passwd               | string |             |         |
| options              | obj    |             |         |
| pool\_size           | int    |             |         |
| switch               | int    |             |         |
| pool\_change\_event  | int    |             |         |
| report\_pool\_change | int    |             |         |

### Log Config

| Name              | Type   | Explanation | Example |
| ----------------- | ------ | ----------- | ------- |
| path              | string |             |         |
| level             | int    |             |         |
| pool\_size        | int    |             |         |
| buffer\_max\_size | int    |             |         |
| name              | string |             |         |
| reserve\_days     | int    |             |         |
| switch            | int    |             |         |

### Elasticsearch Config

| Name        | Type | Explanation | Example                                               |
| ----------- | ---- | ----------- | ----------------------------------------------------- |
| connections | obj  |             | Please see [Elasticsearch](../database/elasticsearch) |
| switch      | int  |             |                                                       |

### Cross Domain Config

| Name   | Type   | Explanation | Example |
| ------ | ------ | ----------- | ------- |
| origin | string |             |         |
| switch | int    |             |         |

### Storage System Config

| Name          | Type   | Explanation | Example                                |
| ------------- | ------ | ----------- | -------------------------------------- |
| base\_path    | string |             |                                        |
| switch        | int    |             |                                        |
| storage\_path | string |             |                                        |
| types         | array  |             | \['file', 'qiniu', 'alioss']           |
| ext           | obj    |             | Please see [Storage](../other/general) |

### Runtime Monitor Config

| Name   | Type | Explanation        | Example |
| ------ | ---- | ------------------ | ------- |
| switch | int  | Monitor API Switch | 0       |

### AMQP Protocol Config

| Name                 | Type   | Explanation | Example |
| -------------------- | ------ | ----------- | ------- |
| pool\_size           | int    |             |         |
| switch               | int    |             |         |
| prefix               | string |             |         |
| channel\_id          | int    |             |         |
| host                 | string |             |         |
| port                 | int    |             |         |
| user                 | string |             |         |
| passwd               | string |             |         |
| vhost                | string |             |         |
| locale               |        |             |         |
| read\_timeout        |        |             |         |
| keepalive            |        |             |         |
| write\_timeout       |        |             |         |
| heartbeat            |        |             |         |
| pool\_change\_event  |        |             |         |
| report\_pool\_change |        |             |         |

### ENV Fields

| Name                        | Type | Explanation | Example |
| --------------------------- | ---- | ----------- | ------- |
| SERVER\_HOST                |      |             |         |
| SERVER\_PORT                |      |             |         |
| SERVER\_REACTOR\_NUM        |      |             |         |
| SERVER\_WORKER\_NUM         |      |             |         |
| SERVER\_DAEMONIZE           |      |             |         |
| SERVER\_BACKLOG             |      |             |         |
| SERVER\_MAX\_REQUEST        |      |             |         |
| SERVER\_DISPATCH\_MODE      |      |             |         |
| REDIS\_HOST                 |      |             |         |
| REDIS\_PORT                 |      |             |         |
| REDIS\_TIMEOUT              |      |             |         |
| REDIS\_POOL\_SIZE           |      |             |         |
| REDIS\_PASSWD               |      |             |         |
| REDIS\_DB                   |      |             |         |
| REDIS\_SWITCH               |      |             |         |
| REDIS\_PREFIX               |      |             |         |
| MYSQL\_DSN                  |      |             |         |
| MYSQL\_USERNAME             |      |             |         |
| MYSQL\_PASSWD               |      |             |         |
| MYSQL\_POOL\_SIZE           |      |             |         |
| MYSQL\_SWITCH               |      |             |         |
| LOG\_PATH                   |      |             |         |
| LOG\_LEVEL                  |      |             |         |
| LOG\_POOL\_SIZE             |      |             |         |
| LOG\_BUFFER\_MAX\_SIZE      |      |             |         |
| LOG\_NAME                   |      |             |         |
| LOG\_RESERVE\_DAYS          |      |             |         |
| LOG\_SWITCH                 |      |             |         |
| ES\_DEFAULT\_HOST           |      |             |         |
| ES\_SWITCH                  |      |             |         |
| ES\_TIMEOUT                 |      |             |         |
| CORS\_ORIGIN                |      |             |         |
| CORS\_SWITCH                |      |             |         |
| APP\_BASE\_PATH             |      |             |         |
| STORAGE\_SWITCH             |      |             |         |
| STORAGE\_PATH               |      |             |         |
| STORAGE\_TYPES              |      |             |         |
| QINIU\_DEFAULT\_BUCKET      |      |             |         |
| QINIU\_DEFAULT\_ACCESS\_KEY |      |             |         |
| QINIU\_DEFAULT\_SECRET\_KEY |      |             |         |
| QINIU\_DEFAULT\_DOMAIN      |      |             |         |
| TIMEZONE                    |      |             |         |
| MONITOR\_SWITCH             |      |             |         |
