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.

Configurable item

The configurable item is used for the http server bean configuration, except that the class is the property of the http server.

  • class specifies the processing class of Http Server
  • port specifies the port of the Http Server
  • listener specifies other services that are started together, and adds port service listeners, which can be multiple.
    • Rpc starts RPC service
  • on configuration listen event
    • Register events, set up processing listeners for corresponding events, event trigger component calls, use in tasks
  • setting here is the reference Swoole Server Configuration Options
  • pidFile sets the process pid文件 location, the default value is @runtime/swoft.pid
  • mode running mode, refer to the third parameter of the Swoole Server constructor
  • type specifies the type of Socket, supports the fourth parameter of the Swoole Server constructor such as TCP, UDP, TCP6, UDP6, UnixSocket Stream/Dgram, etc.

Basic configuration

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

/docs/2.x/en/http-server/setting.html
progress-bar