Http Server configuration parameters
In the application
app/bean.php configuration server, the following lists some simple configuration, you can also freely combine and provide a variety of services.
The configurable item is used for the http server bean configuration, except that the
class is the property of the http server.
classspecifies the processing class of
portspecifies the port of the Http Server
listenerspecifies other services that are started together, and adds port service listeners, which can be multiple.
- Rpc starts
- Rpc starts
onconfiguration listen event
- Register events, set up processing listeners for corresponding events, event trigger component calls, use in tasks
settinghere is the reference Swoole Server Configuration Options
pidFilesets the process
pid文件location, the default value is
moderunning mode, refer to the third parameter of the Swoole Server constructor
typespecifies the type of Socket, supports the fourth parameter of the Swoole Server constructor such as TCP, UDP, TCP6, UDP6, UnixSocket Stream/Dgram, etc.
The Swoft application's Http Server is configured in
app/bean.php . In this file, you can see that the Http Server array contains the basic information of the Http Server.
'httpServer' => [ 'class' => HttpServer::class, 'port' => 18306, /* @see HttpServer::$setting */ 'setting' => [ 'log_file' => alias('@runtime/swoole.log'), ] ],
Enable Task processing
Enable Task process processing tasks
'httpServer' => [ 'class' => HttpServer::class, 'port' => 18306, 'on' => [ // Enable task must task and finish event SwooleEvent::TASK => \bean(TaskListener::class), SwooleEvent::FINISH => \bean(FinishListener::class) ], /* @see HttpServer::$setting */ 'setting' => [ 'task_worker_num' => 12, 'task_enable_coroutine' => true ] ],
Enable RPC support
'httpServer' => [ 'class' => HttpServer::class, 'port' => 18306, 'listener' => [ 'rpc' => \bean('rpcServer') ], /* @see HttpServer::$setting */ 'setting' => [ 'task_worker_num' => 12, 'task_enable_coroutine' => true ] ], 'rpcServer' => [ 'class' => ServiceServer::class, 'port' => 18308, ],
Enable https support
Enabling https support in swowt is also very simple, add the following configuration:
'httpServer' => [ 'type' => SWOOLE_SOCK_TCP | SWOOLE_SSL, /* @see HttpServer::$setting */ 'setting' => [ 'ssl_cert_file' => '/my/certs/2288803_www.domain.com.pem', 'ssl_key_file' => '/my/certs/2288803_www.domain.com.key', ] ]
Note: You must install the OpenSSL library and make sure that the ssl option is enabled when installing swoole. Also, you need to set
'type' => SWOOLE_SOCK_TCP | SWOOLE_SSL