PHP Class MyQEE\Server\Server

主端口可同时支持 WebSocket, Http 协议, 并可以额外监听TCP新端口
Datei anzeigen Open project: myqee/server Class Usage Examples

Public Properties

Property Type Description
$clustersType integer 0 - 无集群, 1 - 简单模式, 2 - 高级模式
$config array 所有的配置
$configFile null 配置文件路径
$instance Server 当前服务器实例化对象
$logPath integer 日志输出设置
$namespace string 用户对象命名空间
$pid integer 主进程的PID
$server Swoole\Server
$serverId integer 服务器ID
$serverMode integer SWOOLE_BASE 或 SWOOLE_PROCESS
$serverType integer * 0 - 主端口自定义协议 * 1 - 主端口只支持 Http * 2 - 主端口只支持 WebSocket * 3 - 主端口同时支持 WebSocket, Http
$worker WorkerMain | WorkerWebSocket | WorkerTCP | WorkerUDP 当前进程对象
$workerTask WorkerTask | WorkerTask 当前任务进程对象
$workers array 所有工作进程对象

Public Methods

Method Description
__construct ( $configFile = 'server.yaml' )
debug ( string | array $labelOrData, array $data = null ) 调试信息
info ( string | array $labelOrData, array $data = null ) 输出信息
log ( string $label, array $data = null, string $type = 'other', string $color = '[36m' ) 输出自定义log
onBeforeStart ( ) 在启动前执行, 可以扩展本方法
onClose ( $server, $fd, $fromId ) 关闭连接回调
onConnect ( $server, $fd, $fromId ) 连接服务器回调
onFinish ( Swoole\Server $server, $taskId, $data ) : mixed
onManagerStart ( Swoole\Server $server )
onMessage ( Swoole\Server $server, Swoole\WebSocket\Frame $frame ) WebSocket 获取消息回调
onOpen ( Swoole\Websocket\Server $svr, Swoole\Http\Request $req ) 当WebSocket客户端与服务器建立连接并完成握手后会回调此函数
onPacket ( $server, $data, $clientInfo ) UDP下收到数据回调
onPipeMessage ( Swoole\Server $server, $fromWorkerId, $message ) : null
onReceive ( Swoole\Server $server, $fd, $fromId, $data )
onRequest ( Swoole\Http\Request $request, Swoole\Http\Response $response ) HTTP 接口请求处理的方法
onStart ( Swoole\Server $server )
onTask ( Swoole\Server $server, $taskId, $fromId, $data ) : mixed
onWorkerStart ( Swoole\Server $server, $workerId ) 进程启动
onWorkerStop ( Swoole\Server $server, $workerId )
setProcessName ( $name ) 设置进程的名称
start ( ) 启动服务
startTaskServer ( ) 启动task服务器
trace ( string | array $labelOrData, array $data = null ) 跟踪信息
warn ( string | array $labelOrData, array $data = null ) 错误信息

Protected Methods

Method Description
bind ( ) 绑定事件
checkConfig ( )
checkSystem ( )
getSockConf ( $key ) : array 获取自定义监听的配置
init ( )
initSockets ( ) 添加的自定义端口服务
parseSockUri ( $uri ) : stdClass 解析Sock的URI
setListenCallback ( string $key, Swoole\Server\Port $listen, stdClass $opt ) 设置自定义端口监听的回调
startWorkerServer ( $config = null )

Private Methods

Method Description
startWithAdvancedClusters ( ) : boolean 高级集群模式启动

Method Details

__construct() public method

public __construct ( $configFile = 'server.yaml' )

bind() protected method

绑定事件
protected bind ( )

checkConfig() protected method

protected checkConfig ( )

checkSystem() protected method

protected checkSystem ( )

debug() public method

调试信息
public debug ( string | array $labelOrData, array $data = null )
$labelOrData string | array
$data array

getSockConf() protected method

获取自定义监听的配置
protected getSockConf ( $key ) : array
$key
return array

info() public method

输出信息
public info ( string | array $labelOrData, array $data = null )
$labelOrData string | array
$data array

init() protected method

protected init ( )

initSockets() protected method

添加的自定义端口服务
protected initSockets ( )

log() public method

输出自定义log
public log ( string $label, array $data = null, string $type = 'other', string $color = '[36m' )
$label string
$data array
$type string
$color string

onBeforeStart() public method

在启动前执行, 可以扩展本方法
public onBeforeStart ( )

onClose() public method

关闭连接回调
public onClose ( $server, $fd, $fromId )
$server
$fd
$fromId

onConnect() public method

连接服务器回调
public onConnect ( $server, $fd, $fromId )
$server
$fd
$fromId

onFinish() public method

public onFinish ( Swoole\Server $server, $taskId, $data ) : mixed
$server Swoole\Server
$taskId
$data
return mixed

onManagerStart() public method

public onManagerStart ( Swoole\Server $server )
$server Swoole\Server

onMessage() public method

WebSocket 获取消息回调
public onMessage ( Swoole\Server $server, Swoole\WebSocket\Frame $frame )
$server Swoole\Server
$frame Swoole\WebSocket\Frame

onOpen() public method

当WebSocket客户端与服务器建立连接并完成握手后会回调此函数
public onOpen ( Swoole\Websocket\Server $svr, Swoole\Http\Request $req )
$svr Swoole\Websocket\Server
$req Swoole\Http\Request

onPacket() public method

UDP下收到数据回调
public onPacket ( $server, $data, $clientInfo )
$server

onPipeMessage() public method

public onPipeMessage ( Swoole\Server $server, $fromWorkerId, $message ) : null
$server Swoole\Server
$fromWorkerId
$message
return null

onReceive() public method

public onReceive ( Swoole\Server $server, $fd, $fromId, $data )
$server Swoole\Server
$fd
$fromId
$data

onRequest() public method

HTTP 接口请求处理的方法
public onRequest ( Swoole\Http\Request $request, Swoole\Http\Response $response )
$request Swoole\Http\Request
$response Swoole\Http\Response

onStart() public method

public onStart ( Swoole\Server $server )
$server Swoole\Server

onTask() public method

public onTask ( Swoole\Server $server, $taskId, $fromId, $data ) : mixed
$server Swoole\Server
$taskId
$fromId
$data
return mixed

onWorkerStart() public method

进程启动
public onWorkerStart ( Swoole\Server $server, $workerId )
$server Swoole\Server
$workerId

onWorkerStop() public method

public onWorkerStop ( Swoole\Server $server, $workerId )
$server Swoole\Server
$workerId

parseSockUri() protected method

解析Sock的URI
protected parseSockUri ( $uri ) : stdClass
$uri
return stdClass

setListenCallback() protected method

设置自定义端口监听的回调
protected setListenCallback ( string $key, Swoole\Server\Port $listen, stdClass $opt )
$key string
$listen Swoole\Server\Port
$opt stdClass

setProcessName() public static method

设置进程的名称
public static setProcessName ( $name )
$name

start() public method

启动服务
public start ( )

startTaskServer() public method

启动task服务器
public startTaskServer ( )

startWorkerServer() protected method

protected startWorkerServer ( $config = null )

trace() public method

跟踪信息
public trace ( string | array $labelOrData, array $data = null )
$labelOrData string | array
$data array

warn() public method

错误信息
public warn ( string | array $labelOrData, array $data = null )
$labelOrData string | array
$data array

Property Details

$clustersType public_oe static_oe property

0 - 无集群, 1 - 简单模式, 2 - 高级模式
public static int $clustersType
return integer

$config public_oe static_oe property

所有的配置
public static array $config
return array

$configFile public_oe static_oe property

配置文件路径
public static null $configFile
return null

$instance public_oe static_oe property

当前服务器实例化对象
public static Server,MyQEE\Server $instance
return Server

$logPath public_oe static_oe property

日志输出设置
public static int $logPath
return integer

$namespace public_oe static_oe property

用户对象命名空间
public static string $namespace
return string

$pid public_oe static_oe property

主进程的PID
public static int $pid
return integer

$server public_oe static_oe property

public static Server,Swoole $server
return Swoole\Server

$serverId public_oe static_oe property

服务器ID
public static int $serverId
return integer

$serverMode public_oe static_oe property

SWOOLE_BASE 或 SWOOLE_PROCESS
See also: http://wiki.swoole.com/wiki/page/14.html
public static int $serverMode
return integer

$serverType public_oe static_oe property

* 0 - 主端口自定义协议 * 1 - 主端口只支持 Http * 2 - 主端口只支持 WebSocket * 3 - 主端口同时支持 WebSocket, Http
public static int $serverType
return integer

$worker public_oe static_oe property

当前进程对象
public static WorkerMain|WorkerWebSocket,MyQEE\Server|WorkerTCP,MyQEE\Server|WorkerUDP,MyQEE\Server $worker
return WorkerMain | WorkerWebSocket | WorkerTCP | WorkerUDP

$workerTask public_oe static_oe property

当前任务进程对象
public static WorkerTask,MyQEE\Server|WorkerTask,MyQEE\Server $workerTask
return WorkerTask | WorkerTask

$workers public_oe static_oe property

所有工作进程对象
public static array $workers
return array