Swoole\Server->set

Declaration

<?php
Swoole\Server->set ( array $settings )

Parameters

settings
  • timeout => 2.5: select and epoll_wait timeout
  • poll_thread_num => 2: eactor thread num
  • max_conn => 10000: the max tcp connection number of the server
  • daemonize => 1: enable the daemon mode the server process
  • reactor_num => 2: set the number of system poll threads, the default setting is the number of CPU cores
  • worker_num => 4: set the number of worker processes
  • max_request => 2000: the number of requests processed by the worker process before been recycled
  • backlog => 128: TCP backlog number, the max number of connections waiting for acception
  • open_cpu_affinity => 1: enable CPU affinity
  • open_tcp_nodelay => 1: enable TCP_NoDelay
  • tcp_defer_accept => 5: delay a period of time for the new connection before been accepted
  • log_file => '/data/log/swoole.log': set the error logs location of the server
  • open_eof_check => true: enable buffer for the data receiving
  • package_eof => "\r\n\r\n": set EOF of the packages
  • heartbeat_check_interval => 30: set the interval of health checking for the TCP connections
  • heartbeat_idle_time => 60: set the max idle time before the idel connection been closed
  • dispatch_mode = 1: dispatch mode for child processes:
    • 1: round robin assignment
    • 2: assignment by mod
    • 3: preemptive assignment
  • log_rotation = SWOOLE_LOG_ROTATION_DAILY: log rotation setting

Check the full list of Swoole server configuration

Return

success

if success, it returns TRUE, otherwise it returns FALSE.

Description

Set the runtime settings of the Swoole server. The settings can be accessed by $server->setting when the Swoole server has started.

Example

<?php
$server->set(array(
    'reactor_num' => 2, //reactor thread num
    'worker_num' => 4,    //worker process num
    'backlog' => 128,   //listen backlog
    'max_request' => 50,
    'dispatch_mode' => 1,
));