\

Classes

swoole_atomic Atomic operation for swoole server.
swoole_buffer Memory Operations for binary & string
swoole_client Http client
swoole_http_request Http request object
swoole_http_response Http response object
swoole_http_server Built-in Web server
swoole_lock Locking operation for swoole server.
swoole_process Swoole Process Management
swoole_server TCP / UDP Server
swoole_table Create a memory table
swoole_websocket_server Websocket server

Constants

HTTP_GLOBAL_ALL

HTTP_GLOBAL_ALL

swoole_http_server : setGlobal all

HTTP_GLOBAL_GET

HTTP_GLOBAL_GET

swoole_http_server : setGlobal GET

HTTP_GLOBAL_POST

HTTP_GLOBAL_POST

swoole_http_server : setGlobal POST

SWOOLE_ASYNC

SWOOLE_ASYNC

?? : Async client

SWOOLE_BASE

SWOOLE_BASE

swoole_server mode : use the base model, code directly executed in Reactor

SWOOLE_EVENT_READ

SWOOLE_EVENT_READ

SWOOLE_EVENT_WRITE

SWOOLE_EVENT_WRITE

SWOOLE_FILELOCK

SWOOLE_FILELOCK

swoole_lock : create a file lock

SWOOLE_KEEP

SWOOLE_KEEP

swoole_client : Keepalive Connection

SWOOLE_MUTEX

SWOOLE_MUTEX

swoole_lock : create a mutex

SWOOLE_PACKET

SWOOLE_PACKET

swoole_client : ??

SWOOLE_PROCESS

SWOOLE_PROCESS

swoole_server mode : use process models, code execution in different process

SWOOLE_RWLOCK

SWOOLE_RWLOCK

swoole_lock : create a read-write lock

SWOOLE_SEM

SWOOLE_SEM

swoole_lock : Create Semaphore

SWOOLE_SOCK_ASYNC

SWOOLE_SOCK_ASYNC

swoole_client : Async client

SWOOLE_SOCK_SYNC

SWOOLE_SOCK_SYNC

swoole_client : Sync client

SWOOLE_SOCK_TCP

SWOOLE_SOCK_TCP

swoole_server type : Create tcp socket

SWOOLE_SOCK_TCP6

SWOOLE_SOCK_TCP6

swoole_server type : Create tcp ipv6 socket

SWOOLE_SOCK_UDP

SWOOLE_SOCK_UDP

swoole_server type : Create udp socket

SWOOLE_SOCK_UDP6

SWOOLE_SOCK_UDP6

swoole_server type : Create udp ipv6 socket

SWOOLE_SOCK_UNIX_DGRAM

SWOOLE_SOCK_UNIX_DGRAM

swoole_server type : Create unix dgram

SWOOLE_SOCK_UNIX_STREAM

SWOOLE_SOCK_UNIX_STREAM

swoole_server type : Create unix stream

SWOOLE_SPINLOCK

SWOOLE_SPINLOCK

swoole_lock : create spin locks

SWOOLE_SSL

SWOOLE_SSL

swoole_server & swoole_client : ssl

SWOOLE_SYNC

SWOOLE_SYNC

?? : Async client

SWOOLE_TCP

SWOOLE_TCP

swoole_server type : Create tcp socket

SWOOLE_TCP6

SWOOLE_TCP6

swoole_server type : Create tcp ipv6 socket

SWOOLE_THREAD

SWOOLE_THREAD

swoole_server mode : using threads models, code execution in thread

SWOOLE_UDP

SWOOLE_UDP

swoole_server type : Create udp socket

SWOOLE_UDP6

SWOOLE_UDP6

swoole_server type : Create udp ipv6 socket

SWOOLE_UNIX_DGRAM

SWOOLE_UNIX_DGRAM

swoole_server type : Create unix dgram

SWOOLE_UNIX_STREAM

SWOOLE_UNIX_STREAM

swoole_server type : Create unix stream

SWOOLE_VERSION

SWOOLE_VERSION

current Swoole version

WEBSOCKET_OPCODE_TEXT

WEBSOCKET_OPCODE_TEXT

swoole_websocket_server : ??

Functions

swoole_async_dns_lookup()

swoole_async_dns_lookup(string  $domain, callable  $callback) 

Asynchronous dns lookup

This function will return immediately after the call. The callback function must accept 2 arguments ($host, $ip)

Parameters

string $domain
callable $callback

swoole_async_read()

swoole_async_read(string  $filename, mixed  $callback, integer  $trunk_size = 8192) : boolean

Asynchronous read file

This function will return immediately after the call. The callback function must accept 2 arguments ($filename, $content)

This function can be used to read large file since the data is chunk with $trunk_size unlike swoole_async_readfile and will not take up too much memory

On the callback function, you can return true / false, to control whether to continue to read the next part Return true, continue to read Return false, stop reading and close the file

Parameters

string $filename
mixed $callback
integer $trunk_size

Returns

boolean

swoole_async_readfile()

swoole_async_readfile(string  $filename, mixed  $callback) 

Asynchronous read file contents

This function will return immediately after the call. The callback function must accept 2 arguments ($filename, $content)

swoole_async_readfile will copy all the contents of the file into memory, it can not be used to read large files. If you want to read large files, use swoole_async_read. THis function read max 4M and is limited by SW_AIO_MAX_FILESIZE

Parameters

string $filename
mixed $callback

swoole_async_write()

swoole_async_write(string  $filename, string  $content, integer  $offset, mixed  $callback = NULL) : boolean

Asynchronous write files

This function will return immediately after the call. The callback function must accept 1 argument ($filename)

This fonction can be used to write large files, but you need to specify the $offset in order to write it

Parameters

string $filename
string $content
integer $offset
mixed $callback

Returns

boolean

swoole_async_writefile()

swoole_async_writefile(string  $filename, string  $content, callable  $callback) 

Asynchronous write files

This function will return immediately after the call. The callback function must accept 1 argument ($filename)

THis function write max 4M and is limited by SW_AIO_MAX_FILESIZE

Parameters

string $filename
string $content
callable $callback

swoole_client_select()

swoole_client_select(array  $read, array  $write, array  $error, float  $timeout) : integer

Io Event loop

Parallel processing of swoole_client using a select IO event loop

$read, $write, $error must be a reference array and must contains swoole_client object. On success, it will return the number of events, and modify the $read / $write / $error array. Use foreach loop through the array, and then execute $item->recv / $item->send to send and receive data. Calling $item->close() or unset($item) will close the socket.

Parameters

array $read

readable file descriptor

array $write

writable file descriptor

array $error

error file descriptor

float $timeout

timeout in second that accept float values

Returns

integer —

yjer

swoole_connection_info()

swoole_connection_info(\swoole_server  $serv, integer  $fd) : array

Parameters

\swoole_server $serv
integer $fd

Returns

array —

on success or false on failure.

swoole_connection_list()

swoole_connection_list(\swoole_server  $serv, integer  $start_fd, integer  $pagesize = 10) : array

Parameters

\swoole_server $serv
integer $start_fd
integer $pagesize

Returns

array —

on success or false on failure

swoole_errno()

swoole_errno() : integer

Get the last error, equivalent to C / C ++ the errno variable.

Returns

integer

swoole_event_add()

swoole_event_add(integer  $sock, callable  $read_callback = NULL, callable  $write_callback = NULL,   $flag = NULL) : boolean

Add a event listener for a socket

Can be used with swoole_server or swoole_client callable can be a string, an object + method, static class methods or anonymous function, when an event appends, the callback is called

Parameters

integer $sock

file descriptor for the socket

callable $read_callback
callable $write_callback
$flag

Returns

boolean

swoole_event_del()

swoole_event_del(integer  $sock) : boolean

Removed an events

must be used after swoole_event_add

Parameters

integer $sock

Returns

boolean

swoole_event_exit()

swoole_event_exit() : void

退出事件轮询

swoole_event_set()

swoole_event_set(integer  $sock, callable  $read_callback = NULL, callable  $write_callback = NULL, null  $flag = NULL) 

Modify a socket event settings

You can modify the read / write callback and the event type

Parameters

integer $sock
callable $read_callback
callable $write_callback
null $flag

swoole_event_wait()

swoole_event_wait() : void

Event polling

Lower than version 5.4, you need add swoole_event_wait function at the end of your PHP script in order starts event polling. 5.4 or later you do not need to add this function.

swoole_event_write()

swoole_event_write(mixed  $socket, string  $data) 

Asynchronous write

Parameters

mixed $socket
string $data

swoole_get_local_ip()

swoole_get_local_ip() : array

Get all ip address on all network interface

Currently only IPv4 addresses returned and will filter out the local address 127.0.0.1.

Result is an associative array where the interface name is the key.

array("eth0" => "192.168.1.100")

Returns

array

swoole_get_mysqli_sock()

swoole_get_mysqli_sock(\mysqli  $db) : integer

 * Get an asynchronous MySQLi socket file descriptor  *  * If you want to use asynchronous MySQL, you need to compile swoole with --enable-async-mysql  * swoole_get_mysqli_sock does not support mysqlnd driver, so php5.4+ versions is not support

Parameters

\mysqli $db

Returns

integer

swoole_server_addlisten()

swoole_server_addlisten(\swoole_server  $serv, string  $host = '127.0.0.1', integer  $port = 9502) : void

Parameters

\swoole_server $serv
string $host
integer $port

swoole_server_addtimer()

swoole_server_addtimer(\swoole_server  $serv, integer  $interval) : boolean

Parameters

\swoole_server $serv
integer $interval

Returns

boolean

swoole_server_close()

swoole_server_close(\swoole_server  $serv, integer  $fd, integer  $from_id) : boolean

Parameters

\swoole_server $serv
integer $fd
integer $from_id

Returns

boolean

swoole_server_create()

swoole_server_create(string  $host, integer  $port, integer  $mode = SWOOLE_PROCESS, integer  $sock_type = SWOOLE_SOCK_TCP) 

Parameters

string $host
integer $port
integer $mode

SWOOLE_BASE, SWOOLE_THREAD, SWOOLE_PROCESS, SWOOLE_PACKET

integer $sock_type

SWOOLE_SOCK_TCP, SWOOLE_SOCK_TCP6, SWOOLE_SOCK_UDP, SWOOLE_SOCK_UDP6, SWOOLE_SOCK_UNIX_DGRAM, SWOOLE_SOCK_UNIX_STREAM, If you want use ssl just or (|) your current socket type with SWOOLE_SSL

swoole_server_finish()

swoole_server_finish(\swoole_server  $serv, string  $response) : void

Parameters

\swoole_server $serv
string $response

swoole_server_handler()

swoole_server_handler(\swoole_server  $serv, string  $event_name, callable  $event_callback_function) : boolean

Parameters

\swoole_server $serv
string $event_name
callable $event_callback_function

Returns

boolean

swoole_server_reload()

swoole_server_reload(\swoole_server  $serv) : void

Parameters

\swoole_server $serv

swoole_server_send()

swoole_server_send(\swoole_server  $serv, integer  $fd, string  $data, integer  $from_id) : boolean

Parameters

\swoole_server $serv
integer $fd
string $data
integer $from_id

Returns

boolean

swoole_server_set()

swoole_server_set(\swoole_server  $serv,   $arguments) 

Parameters

\swoole_server $serv
$arguments

swoole_server_shutdown()

swoole_server_shutdown(\swoole_server  $serv) : void

Parameters

\swoole_server $serv

swoole_server_start()

swoole_server_start(\swoole_server  $serv) : boolean

Parameters

\swoole_server $serv

Returns

boolean

swoole_server_task()

swoole_server_task(\swoole_server  $serv, string  $data) : integer

Parameters

\swoole_server $serv
string $data

Returns

integer —

$task_id

swoole_server_taskwait()

swoole_server_taskwait(string  $task_data, float  $timeout = 0.5) : string

Parameters

string $task_data
float $timeout

Returns

string

swoole_set_process_name()

swoole_set_process_name(string  $name) : void

change current process name

Same that cli_set_process_title but works with PHP 5.2 and above

Parameters

string $name

swoole_strerror()

swoole_strerror(integer  $errno) : string

The standard Unix Errno error code into an error message

Parameters

integer $errno

Returns

string

swoole_timer_add()

swoole_timer_add(  $interval, callable  $callback) : integer

Parameters

$interval
callable $callback

Returns

integer

swoole_timer_after()

swoole_timer_after(integer  $ms, callable  $callback,   $user_param = null) : integer

Parameters

integer $ms
callable $callback
$user_param

Returns

integer

swoole_timer_clear()

swoole_timer_clear(  $timer_id) : boolean

Parameters

$timer_id

Returns

boolean

swoole_timer_del()

swoole_timer_del(  $interval) 

Parameters

$interval

swoole_timer_tick()

swoole_timer_tick(integer  $ms, callable  $callback, null  $params = null) : integer

Parameters

integer $ms
callable $callback
null $params

Returns

integer

swoole_version()

swoole_version() : string

Get swoole extended version number, such as 1.6.10

Returns

string