# \PG\MSFMSFServer

Class MSFServer

## Summary

Methods
Properties
Constants
__construct()
setConfig()
start()
onWorkerStart()
setTemplateEngine()
onRequest()
genLogId()
getTimerContext()
getInstance()
run()
setProcessTitle()
setServerSet()
beforeSwooleStart()
onStart()
onClose()
onWorkerStop()
onTask()
onFinish()
onPipeMessage()
onWorkerError()
onManagerStart()
onManagerStop()
__call()
registerTimer()
displayErrorHandler()
checkErrors()
isTaskWorker()
close()
onErrorHandle()
setContext()
destroy()
initAsynPools()
initRedisProxies()
addAsynPool()
getAsynPool()
addRedisProxy()
getRedisProxy()
setRedisProxy()
getRedisProxies()
statistics()
onInitTimer()
getAllTaskMessage()
$httpSocketName
$httpPort
$httpEnable
$templateEngine
$processType
$daemonize
$pidFile
$scheduler
$name
$user
$workerNum
$taskNum
$tickTime
$pack
$onErrorHandle
$server
$config
$log
$sysCache
$sysTimers
$MSFSrcDir
$objectPool
$objectPoolBuckets
$taskAtomic
$tidPidTable
version
mode
SERVER_NAME
init()
parseCommand()
initWorkers()
getCurrentUser()
displayUI()
startSwooles()
$instance
$_masterPid
$logFile
$_startFile
$_worker
$route
$stdClass
$reflections
$redisProxyManager
$asynPools
$asynPoolManager
N/A
No private methods found
No private properties found
N/A
abstract

File
  MSFServer.php
Package
  PG\MSF
Class hierarchy
  \PG\MSF\Base\Child
  \PG\MSF\Server
  \PG\MSF\HttpServer
  \PG\MSF\MSFServer

## Tags

None found

## Constants

### version

    version

版本

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### mode

    mode

运行方式（web/console）

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### SERVER_NAME

    SERVER_NAME

默认服务名称

#

## Tags

None found

## Properties

### $httpSocketName

    $httpSocketName : string

#### Type

string — HTTP服务监听地址如: 0.0.0.0

#

Inherited from
  \PG\MSF\HttpServer

## Tags

None found

### $httpPort

    $httpPort : integer

#### Type

integer — HTTP服务监听商品

#

Inherited from
  \PG\MSF\HttpServer

## Tags

None found

### $httpEnable

    $httpEnable : boolean

#### Type

boolean — 是否启用HTTP服务

#

Inherited from
  \PG\MSF\HttpServer

## Tags

None found

### $templateEngine

    $templateEngine : \League\Plates\Engine

#### Type

\League\Plates\Engine — 内置模板引擎

#

Inherited from
  \PG\MSF\HttpServer

## Tags

None found

### $processType

    $processType : integer

#### Type

integer — 进程类型，worker,tasker,user

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### $daemonize

    $daemonize : boolean

#### Type

boolean — Daemonize.

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### $pidFile

    $pidFile : string

#### Type

string — pid文件

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### $scheduler

    $scheduler : \PG\MSF\Coroutine\Scheduler

#### Type

\PG\MSF\Coroutine\Scheduler — 协程调度器

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### $name

    $name : string

#### Type

string — server name

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### $user

    $user : string

#### Type

string — server user

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### $workerNum

    $workerNum : integer

#### Type

integer — Worker数量

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### $taskNum

    $taskNum : integer

#### Type

integer — Tasker数量

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### $tickTime

    $tickTime : integer

#### Type

integer — 服务器到现在的毫秒数

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### $pack

    $pack : \PG\MSF\Pack\IPack

#### Type

\PG\MSF\Pack\IPack — 数据打包与解包

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### $onErrorHandle

    $onErrorHandle : callback

#### Type

callback — 错误回调

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### $server

    $server : \swoole_server

#### Type

\swoole_server — Server运行实例

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### $config

    $config : \Noodlehaus\Config

#### Type

\Noodlehaus\Config — 配置对象

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### $log

    $log : \PG\Log\PGLog

#### Type

\PG\Log\PGLog — 日志对象

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### $sysCache

    $sysCache : \Yac

#### Type

\Yac — 系统共享对象操作句柄

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### $sysTimers

    $sysTimers : array

系统注册的定时器列表

#### Type

array

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### $MSFSrcDir

    $MSFSrcDir : string

#### Type

string — 框架目录

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### $objectPool

    $objectPool : \PG\MSF\Base\Pool

#### Type

\PG\MSF\Base\Pool — 对象池

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### $objectPoolBuckets

    $objectPoolBuckets :

var array Tasker进程内对象容器

#### Type

#

## Tags

None found

### $taskAtomic

    $taskAtomic : \swoole_atomic

#### Type

\swoole_atomic — task_id的原子

#

## Tags

None found

### $tidPidTable

    $tidPidTable : array

#### Type

array — task_id和pid的映射

#

## Tags

None found

### $instance

    $instance : \PG\MSF\Server

#### Type

\PG\MSF\Server — 实例

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### $_masterPid

    $_masterPid : integer

#### Type

integer — Master进程ID

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### $logFile

    $logFile : mixed

#### Type

mixed — 日志文件

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### $_startFile

    $_startFile : string

#### Type

string — Start file.

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### $_worker

    $_worker : \PG\MSF\Server

#### Type

\PG\MSF\Server — worker instance.

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### $route

    $route : \PG\MSF\Route\IRoute|\PG\MSF\Route\NormalRoute

#### Type

\PG\MSF\Route\IRoute|\PG\MSF\Route\NormalRoute — 路由器

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### $stdClass

    $stdClass : \stdClass|null

#### Type

\stdClass|null — 对象模板

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### $reflections

    $reflections : array

#### Type

array — 反射类属性的默认值

#

Inherited from
  \PG\MSF\Base\Child

## Tags

None found

### $redisProxyManager

    $redisProxyManager : array

#### Type

array — Redis代理管理器

#

## Tags

None found

### $asynPools

    $asynPools : array

#### Type

array — 连接池

#

## Tags

None found

### $asynPoolManager

    $asynPoolManager : \PG\MSF\Pools\AsynPoolManager

#### Type

\PG\MSF\Pools\AsynPoolManager — 连接池管理器

#

## Tags

None found

## Methods

### __construct()

    __construct()

MSFServer constructor.

#

## Tags

None found

### setConfig()

    setConfig() : $this

设置并解析配置

#### Returns

$this

#

## Tags

None found

### start()

    start() : $this|void

启动服务

#### Returns

$this|void

#

## Tags

None found

### onWorkerStart()

    onWorkerStart(\swoole_server  $serv, integer  $workerId)

添加异步redis,添加redisProxy

#### Parameters

\swoole_server | $serv | server实例
integer | $workerId | worker id

#### Throws

\Exception

#

## Tags

None found

### setTemplateEngine()

    setTemplateEngine() : $this

设置模板引擎

#### Returns

$this

#

Inherited from
  \PG\MSF\HttpServer

## Tags

None found

### onRequest()

    onRequest(\swoole_http_request  $request, \swoole_http_response  $response)

HTTP请求回调

#### Parameters

\swoole_http_request | $request | 请求对象
\swoole_http_response | $response | 响应对象

#

Inherited from
  \PG\MSF\HttpServer

## Tags

None found

### genLogId()

    genLogId(\swoole_http_request  $request) : string

产生日志ID

#### Parameters

\swoole_http_request | $request | 请求对象

#### Returns

string

#

Inherited from
  \PG\MSF\HttpServer

## Tags

None found

### getTimerContext()

    getTimerContext() : NULL|\PG\MSF\Helpers\Context

创建用户自定义定时进程的上下文对象

#### Returns

NULL|\PG\MSF\Helpers\Context

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### getInstance()

    getInstance() : \PG\MSF\Server|\PG\MSF\MSFServer

获取运行的Server实例

#### Returns

\PG\MSF\Server|\PG\MSF\MSFServer

#

static

Inherited from
  \PG\MSF\Server

## Tags

None found

### run()

    run() : void

运行所有的服务进程

#

static

Inherited from
  \PG\MSF\Server

## Tags

None found

### setProcessTitle()

    setProcessTitle(string  $title) : void

设置服务进程名称

#### Parameters

string | $title |

#

static

Inherited from
  \PG\MSF\Server

## Tags

None found

### setServerSet()

    setServerSet() : array

设置服务器配置参数

#### Returns

array

#

## Tags

None found

### beforeSwooleStart()

    beforeSwooleStart()

服务启动前的初始化

#

## Tags

None found

### onStart()

    onStart(  $serv)

Server启动在主进程的主线程回调此函数

#### Parameters

| $serv |

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### onClose()

    onClose(\swoole_server  $serv,   $fd)

连接断开

#### Parameters

\swoole_server | $serv |
| $fd |

#

## Tags

None found

### onWorkerStop()

    onWorkerStop(  $serv,   $fd)

此事件在worker进程终止时发生

#### Parameters

| $serv |
| $fd |

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### onTask()

    onTask(\swoole_server  $serv, integer  $taskId, integer  $fromId, array  $data) : mixed|null

异步Task任务回调

#### Parameters

\swoole_server | $serv |
integer | $taskId | Task ID
integer | $fromId | 来自于哪个worker进程
array | $data | 任务的内容

#### Throws

\Exception

#### Returns

mixed|null

#

## Tags

None found

### onFinish()

    onFinish(  $serv,   $taskId,   $data)

当worker进程投递的任务在task_worker中完成时调用

#### Parameters

| $serv |
| $taskId |
| $data |

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### onPipeMessage()

    onPipeMessage(\swoole_server  $serv, integer  $fromWorkerId, string  $message)

PipeMessage

#### Parameters

\swoole_server | $serv | server实例
integer | $fromWorkerId | worker id
string | $message | 消息内容

#

## Tags

None found

### onWorkerError()

    onWorkerError(\swoole_server  $serv, integer  $workerId, integer  $workerPid, integer  $exitCode)

当worker/task_worker进程发生异常后会在Manager进程内回调此函数。

#### Parameters

\swoole_server | $serv | server实例
integer | $workerId | worker id
integer | $workerPid | worker pid
integer | $exitCode | 退出状态码

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### onManagerStart()

    onManagerStart(  $serv)

当管理进程启动时调用

#### Parameters

| $serv |

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### onManagerStop()

    onManagerStop(  $serv)

当管理进程结束时调

#### Parameters

| $serv |

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### __call()

    __call(  $name,   $arguments) : mixed

__call魔术方法

#### Parameters

| $name |
| $arguments |

#### Returns

mixed

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### registerTimer()

    registerTimer(integer  $ms, callable  $callBack, array  $params = array())

定时器包装（用于业务Timer进程）

#### Parameters

integer | $ms | 定时器间隔毫秒
callable | $callBack | 定时器执行的回调
array | $params | 定时器其他参数

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### displayErrorHandler()

    displayErrorHandler(integer  $error, string  $errorString, string  $filename, integer  $line, array  $symbols)

全局错误监听

#### Parameters

integer | $error | 错误码
string | $errorString | 错误描述
string | $filename | 文件名
integer | $line | 文件行
array | $symbols | 符号表

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### checkErrors()

    checkErrors() : void

致命错误回调

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### isTaskWorker()

    isTaskWorker() : boolean

是否是task进程

#### Returns

boolean

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### close()

    close(integer  $fd)

服务器主动关闭链接

#### Parameters

integer | $fd |

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### onErrorHandle()

    onErrorHandle(  $msg,   $log)

错误处理函数

#### Parameters

| $msg |
| $log |

#

Inherited from
  \PG\MSF\Server

## Tags

None found

### setContext()

    setContext(\PG\MSF\Helpers\Context  $context) : $this

设置上下文

#### Parameters

\PG\MSF\Helpers\Context | $context | 请求上下文对象

#### Returns

$this

#

Inherited from
  \PG\MSF\Base\Child

## Tags

None found

### destroy()

    destroy()

销毁,解除引用

#

Inherited from
  \PG\MSF\Base\Child

## Tags

None found

### initAsynPools()

    initAsynPools()

初始化连接池

#

## Tags

None found

### initRedisProxies()

    initRedisProxies()

初始化redis代理客户端

#

## Tags

None found

### addAsynPool()

    addAsynPool(string  $name, \PG\MSF\Pools\AsynPool  $pool, boolean  $isRegister = false) : $this

手工添加AsynPool

#### Parameters

string | $name | 连接池名称
\PG\MSF\Pools\AsynPool | $pool | 连接池对象
boolean | $isRegister | 是否注册到asynPoolManager

#### Throws

\Exception

#### Returns

$this

#

## Tags

None found

### getAsynPool()

    getAsynPool(string  $name) : \PG\MSF\Pools\AsynPool

获取连接池

#### Parameters

string | $name | 连接池名称

#### Returns

\PG\MSF\Pools\AsynPool

#

## Tags

None found

### addRedisProxy()

    addRedisProxy(string  $name, \PG\MSF\Proxy\IProxy  $proxy) : $this

手工添加redis代理

#### Parameters

string | $name | 代理名称
\PG\MSF\Proxy\IProxy | $proxy | 代理实例

#### Throws

\Exception

#### Returns

$this

#

## Tags

None found

### getRedisProxy()

    getRedisProxy(string  $name) : mixed

获取redis代理

#### Parameters

string | $name | 代理名称

#### Returns

mixed

#

## Tags

None found

### setRedisProxy()

    setRedisProxy(string  $name, \PG\MSF\Proxy\IProxy  $proxy) : $this

设置redis代理

#### Parameters

string | $name | 代理名称
\PG\MSF\Proxy\IProxy | $proxy | 代理实例

#### Returns

$this

#

## Tags

None found

### getRedisProxies()

    getRedisProxies() : array

获取所有的redisProxy

#### Returns

array

#

## Tags

None found

### statistics()

    statistics() : array

Worker进程统计信息

#### Returns

array

#

## Tags

None found

### onInitTimer()

    onInitTimer() : mixed

初始化自定义业务定时器（在独立进程中）

#### Returns

mixed

#

## Tags

None found

### getAllTaskMessage()

    getAllTaskMessage() : array

获取正在运行的Task

#### Returns

array

#

## Tags

None found

### init()

    init() : void

服务初始化

#

static

Inherited from
  \PG\MSF\Server

## Tags

None found

### parseCommand()

    parseCommand() : void

解析命令行参数

#

static

Inherited from
  \PG\MSF\Server

## Tags

None found

### initWorkers()

    initWorkers() : void

初始化worker进程

#

static

Inherited from
  \PG\MSF\Server

## Tags

None found

### getCurrentUser()

    getCurrentUser() : string

获取当前进程用户

#### Returns

string

#

static

Inherited from
  \PG\MSF\Server

## Tags

None found

### displayUI()

    displayUI() : void

显示命令行控制台信息

#

static

Inherited from
  \PG\MSF\Server

## Tags

None found

### startSwooles()

    startSwooles() : void

Fork some worker processes.

#

static

Inherited from
  \PG\MSF\Server

## Tags

None found

### MSFServer.php