This repository was archived by the owner on Mar 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 390
5. Configuration
Albert Chen edited this page Apr 29, 2018
·
18 revisions
If you want to change the default configurations, please run the following command to generate configuration files swoole_http.php
and swoole_websocket.php
in directory config/
:
$ php artisan vendor:publish --tag=laravel-swoole
For Lumen users, you need to copy those files to
config
folder and register them inbootstrap/app.php
manually.
Key | Description |
---|---|
server.host |
Server listening host address |
server.port |
Server listening port |
server.options |
The configurations for Swoole\Server . To get more information about swoole server, please read the official documentation
|
websocket.enabled |
Determine if to enable websocket server |
sandbox_mode |
Determine if process your request under sandbox mode. It's enabled by default. |
ob_output |
Console output will be transfered to response content if enabled. |
providers |
Providers here will be registered on every request. |
instances |
Instances here will be cleared on every request. |
facades |
Resolved facades here will be cleared on every request. |
tables |
You are able to define your swoole tables for data sharing cross processes here. |
Here are some examples:
[
'server' => [
// Options here will pass to Swoole server's configuration directly
'options' => [
'max_request' => 1000,
],
// You can run your application in deamon
'daemonize' => env('SWOOLE_HTTP_DAEMONIZE', false),
// Normally this value should be 1~4 times lager according to your cpu cores
'worker_num' => env('SWOOLE_HTTP_WORKER_NUM', 4),
// This value should be larger than `post_max_size` and `upload_max_filesize` in `php.ini`.
// This equals to 10 MB
'buffer_output_size' => 10 * 1024 * 1024
],
// The service providers you want to reset on every request. It will re-register and reboot those service providers before requesting every time.
'providers' => [
Illuminate\Auth\AuthServiceProvider::class,
],
// You can customize your swoole tables here.
// See https://wiki.swoole.com/wiki/page/p-table.html for more detailed information.
'tables' => [
'table_name' => [
'size' => 1024,
'columns' => [
['name' => 'column_name', 'type' => Table::TYPE_STRING, 'size' => 1024],
]
],
]
]
Key | Description |
---|---|
handler |
Websocket handler for onOpen and onClose callback function |
route_file |
Websocket route file path |
default |
Default websocket room driver |
parser |
Default websocket frame parser |
ping_interval |
Websocket client's heartbeat interval (ms) |
ping_timeout |
Websocket client's heartbeat interval timeout (ms) |
drivers |
Room drivers mapping |
settings |
Room drivers settings |
Here are some examples:
[
// Replace this handler if you want to customize your websocket handler
'handler' => SwooleTW\Http\Websocket\SocketIO\WebsocketHandler::class,
// You can register your websocket event mapping in this route file
'route_file' => base_path('routes/websocket.php'),
// Default room driver, it's `table`(swoole table) by default
'default' => 'table',
// Don't forget to add the driver mapping here if you want to use your own driver
'drivers' => [
'table' => SwooleTW\Http\Websocket\Rooms\TableRoom::class,
'redis' => SwooleTW\Http\Websocket\Rooms\RedisRoom::class,
],
// Room driver's settings
'settings' => [
// Memory of swoole table is allocated in the very begining of the process.
// You can't modify it after starting server.
// So you should set them to proper values
'table' => [
'room_rows' => 4096,
'room_size' => 2048,
'client_rows' => 8192,
'client_size' => 2048
],
],
]