# The Swoole\Server class

(PECL swoole >= 1.9.0)

## Introduction

## Class synopsis

class Swoole\Server {
/* Methods */
public addlistener(string `$host`, int `$port`, string `$socket_type`): void
public addProcess(swoole_process `$process`): bool
public after(int `$after_time_ms`, callable `$callback`, string `$param` = ?): ReturnType
public bind(int `$fd`, int `$uid`): bool
public clearTimer(int `$timer_id`): void
swoole_timer_clear(int `$timer_id`): void
public close(int `$fd`, bool `$reset` = ?): bool
public confirm(int `$fd`): bool
public connection_info(int `$fd`, int `$reactor_id` = ?): array
public connection_list(int `$start_fd`, int `$pagesize` = ?): array
public defer(callable `$callback`): void
public exist(int `$fd`): bool
public finish(string `$data`): void
public getClientInfo(int `$fd`, int `$reactor_id` = ?, bool `$ignore_error` = ?): array
public getClientList(int `$start_fd`, int `$pagesize` = ?): array
public getLastError(): int
public heartbeat(bool `$if_close_connection`): mixed
public listen(string `$host`, int `$port`, string `$socket_type`): bool
public on(string `$event_name`, callable `$callback`): void
public pause(int `$fd`): void
public protect(int `$fd`, bool `$is_protected` = ?): void
public reload(): bool
public resume(int `$fd`): void
public send(int `$fd`, string `$data`, int `$reactor_id` = ?): bool
public sendfile(int `$fd`, string `$filename`, int `$offset` = ?): bool
public sendMessage(int `$worker_id`, string `$data`): bool
public sendto(
string `$ip`,
int `$port`,
string `$data`,
string `$server_socket` = ?
): bool
public sendwait(int `$fd`, string `$data`): bool
public set(array `$settings`): ReturnType
public shutdown(): void
public start(): void
public stats(): array
public stop(int `$worker_id` = ?): bool
public task(string `$data`, int `$dst_worker_id` = ?, callable `$callback` = ?): mixed
public taskwait(string `$data`, float `$timeout` = ?, int `$worker_id` = ?): void
public taskWaitMulti(array `$tasks`, float `$timeout_ms` = ?): void
public tick(int `$interval_ms`, callable `$callback`): void
}

## Table of Contents

- Swoole\Server::addlistener — Add a new listener to the server.
- Swoole\Server::addProcess — Add a user defined swoole_process to the server.
- Swoole\Server::after — Trigger a callback function after a period of time.
- Swoole\Server::bind — Bind the connection to a user defined user ID.
- Swoole\Server::clearTimer — Stop and destroy a timer.
- Swoole\Server::close — Close a connection to the client.
- Swoole\Server::confirm — Check status of the connection.
- Swoole\Server::connection_info — Get the connection info by file description.
- Swoole\Server::connection_list — Get all of the established connections.
- Swoole\Server::__construct — Construct a Swoole server.
- Swoole\Server::defer — Delay execution of the callback function at the end of current EventLoop.
- Swoole\Server::exist — Check if the connection is existed.
- Swoole\Server::finish — Used in task process for sending result to the worker process when the task is finished.
- Swoole\Server::getClientInfo — Get the connection info by file description.
- Swoole\Server::getClientList — Get all of the established connections.
- Swoole\Server::getLastError — Get the error code of the most recent error.
- Swoole\Server::heartbeat — Check all the connections on the server.
- Swoole\Server::listen — Listen on the given IP and port, socket type.
- Swoole\Server::on — Register a callback function by event name.
- Swoole\Server::pause — Stop receiving data from the connection.
- Swoole\Server::protect — Set the connection to be protected mode.
- Swoole\Server::reload — Restart all the worker process.
- Swoole\Server::resume — Start receiving data from the connection.
- Swoole\Server::send — Send data to the client.
- Swoole\Server::sendfile — Send file to the connection.
- Swoole\Server::sendMessage — Send message to worker processes by ID.
- Swoole\Server::sendto — Send data to the remote UDP address.
- Swoole\Server::sendwait — Send data to the remote socket in the blocking way.
- Swoole\Server::set — Set the runtime settings of the swoole server.
- Swoole\Server::shutdown — Shutdown the master server process, this function can be called in worker processes.
- Swoole\Server::start — Start the Swoole server.
- Swoole\Server::stats — Get the stats of the Swoole server.
- Swoole\Server::stop — Stop the Swoole server.
- Swoole\Server::task — Send data to the task worker processes.
- Swoole\Server::taskwait — Send data to the task worker processes in blocking way.
- Swoole\Server::taskWaitMulti — Execute multiple tasks concurrently.
- Swoole\Server::tick — Repeats a given function at every given time-interval.

`↑` and `↓` to navigate • `Enter` to select • `Esc` to close • `/` to open