PHP Class Bootstrap\Worker

Show file Open project: smalleyes/statistics Class Usage Examples

Public Properties

Property Type Description
$instance

Protected Properties

Property Type Description
$_maxManagerPidLength
$_maxMasterPidLength integer MasterPid命令时格式化输出 ManagerPid命令时格式化输出 WorkerId命令时格式化输出 WorkerPid命令时格式化输出
$_maxWorkerIdLength
$_maxWorkerPidLength
$handleProviderPort
$handleWorkerPort
$logBuffer string 日志的buffer
$logDir string 存放统计日志的目录
$masterPidPath string master pid path
$statisticData array 统计数据 ip=>modid=>interface=>['code'=>[xx=>count,xx=>count],'suc_cost_time'=>xx,'fail_cost_time'=>xx, 'suc_count'=>xx, 'fail_count'=>xx]
$statisticDir string 存放统计数据的目录
$udpFinderport

Public Methods

Method Description
__construct ( )
clearDisk ( string $file = null, integer $exp_time = 86400 ) 清除磁盘数据
decode ( unknown $buffer ) : mixed 解包
getRedis ( ) : unknown 返回redis链接资源
log ( unknown $msg ) 日志
onClose ( unknown $serv, unknown $fd, unknown $from_id ) 链接断开
onConnect ( swoole_server $serv, unknown $fd, unknown $from_id ) 建立链接
onFinish ( swoole_server $serv, unknown $task_id, unknown $data ) task执行完毕调用
onReceive ( swoole_server $serv, unknown $fd, unknown $from_id, unknown $data ) 接收数据
onShutdown ( unknown $serv ) 关闭服务器
onStart ( swoole_server $serv ) swoole_start 回调函数
onTask ( swoole_server $serv, unknown $task_id, unknown $from_id, unknown $data ) : void | multitype:string task任务
onWorkerError ( swoole_server $serv, unknown $worker_id, unknown $worker_pid, unknown $exit_code ) worker出现问题调用
onWorkerStart ( unknown $serv, unknown $worker_id ) 进程启动
onWorkerStop ( unknown $serv, unknown $worker_id ) 关闭进程
processRename ( unknown $serv, unknown $worker_id ) 修改进程名
run ( $ip = "0.0.0.0", $port = 55656, $mode = SWOOLE_PROCESS, $type = SWOOLE_SOCK_TCP )
writeLogToDisk ( ) : void 将日志数据写入磁盘
writeStatisticsToDisk ( ) : void 将统计数据写入磁盘

Protected Methods

Method Description
collectStatistics ( string $module, string $interface, float $cost_time, integer $success, string $ip, integer $code, string $msg ) : void 收集统计数据

Method Details

__construct() public method

public __construct ( )

clearDisk() public method

清除磁盘数据
public clearDisk ( string $file = null, integer $exp_time = 86400 )
$file string
$exp_time integer

collectStatistics() protected method

收集统计数据
protected collectStatistics ( string $module, string $interface, float $cost_time, integer $success, string $ip, integer $code, string $msg ) : void
$module string
$interface string
$cost_time float
$success integer
$ip string
$code integer
$msg string
return void

decode() public static method

解包
public static decode ( unknown $buffer ) : mixed
$buffer unknown
return mixed

getRedis() public method

返回redis链接资源
public getRedis ( ) : unknown
return unknown

log() public method

日志
public log ( unknown $msg )
$msg unknown

onClose() public method

链接断开
public onClose ( unknown $serv, unknown $fd, unknown $from_id )
$serv unknown
$fd unknown
$from_id unknown

onConnect() public method

建立链接
public onConnect ( swoole_server $serv, unknown $fd, unknown $from_id )
$serv swoole_server
$fd unknown
$from_id unknown

onFinish() public method

task执行完毕调用
public onFinish ( swoole_server $serv, unknown $task_id, unknown $data )
$serv swoole_server
$task_id unknown
$data unknown

onReceive() public method

接收数据
public onReceive ( swoole_server $serv, unknown $fd, unknown $from_id, unknown $data )
$serv swoole_server
$fd unknown
$from_id unknown
$data unknown

onShutdown() public method

关闭服务器
public onShutdown ( unknown $serv )
$serv unknown

onStart() public method

swoole_start 回调函数
public onStart ( swoole_server $serv )
$serv swoole_server

onTask() public method

task任务
public onTask ( swoole_server $serv, unknown $task_id, unknown $from_id, unknown $data ) : void | multitype:string
$serv swoole_server
$task_id unknown
$from_id unknown
$data unknown
return void | multitype:string

onWorkerError() public method

worker出现问题调用
public onWorkerError ( swoole_server $serv, unknown $worker_id, unknown $worker_pid, unknown $exit_code )
$serv swoole_server
$worker_id unknown
$worker_pid unknown
$exit_code unknown

onWorkerStart() public method

进程启动
public onWorkerStart ( unknown $serv, unknown $worker_id )
$serv unknown
$worker_id unknown

onWorkerStop() public method

关闭进程
public onWorkerStop ( unknown $serv, unknown $worker_id )
$serv unknown
$worker_id unknown

processRename() public method

修改进程名
public processRename ( unknown $serv, unknown $worker_id )
$serv unknown
$worker_id unknown

run() public method

public run ( $ip = "0.0.0.0", $port = 55656, $mode = SWOOLE_PROCESS, $type = SWOOLE_SOCK_TCP )

writeLogToDisk() public method

将日志数据写入磁盘
public writeLogToDisk ( ) : void
return void

writeStatisticsToDisk() public method

将统计数据写入磁盘
public writeStatisticsToDisk ( ) : void
return void

Property Details

$_maxManagerPidLength protected static property

protected static $_maxManagerPidLength

$_maxMasterPidLength protected static property

MasterPid命令时格式化输出 ManagerPid命令时格式化输出 WorkerId命令时格式化输出 WorkerPid命令时格式化输出
protected static int $_maxMasterPidLength
return integer

$_maxWorkerIdLength protected static property

protected static $_maxWorkerIdLength

$_maxWorkerPidLength protected static property

protected static $_maxWorkerPidLength

$handleProviderPort protected property

protected $handleProviderPort

$handleWorkerPort protected property

protected $handleWorkerPort

$instance public static property

public static $instance

$logBuffer protected property

日志的buffer
protected string $logBuffer
return string

$logDir protected property

存放统计日志的目录
protected string $logDir
return string

$masterPidPath protected property

master pid path
protected string $masterPidPath
return string

$statisticData protected property

统计数据 ip=>modid=>interface=>['code'=>[xx=>count,xx=>count],'suc_cost_time'=>xx,'fail_cost_time'=>xx, 'suc_count'=>xx, 'fail_count'=>xx]
protected array $statisticData
return array

$statisticDir protected property

存放统计数据的目录
protected string $statisticDir
return string

$udpFinderport protected property

protected $udpFinderport