Properties

$taskName

$taskName : string

Type

string — 执行的Task Name

$taskConstruct

$taskConstruct : array

Type

array — Task构造参数

$__useCount

$__useCount : integer

Type

integer — 作用计数

$__genTime

$__genTime : integer

Type

integer — 创建时间

$__isContruct

$__isContruct : boolean

Type

boolean — 是否执行构造方法

$stdClass

$stdClass : \stdClass|null

Type

\stdClass|null — 对象模板

$timeout

$timeout : integer

Type

integer — 任务执行超时时间

$taskId

$taskId : integer

Type

integer — 任务ID

$__isDestroy

$__isDestroy : boolean

Type

boolean — 销毁标志

$redisPools

$redisPools : array

Type

array — redis连接池

$mysqlPools

$mysqlPools : array

Type

array — mysql连接池

$redisProxies

$redisProxies : array

Type

array — redis代理池

$reflections

$reflections : array

Type

array — 反射类属性的默认值

$mongoConf

$mongoConf : array

Type

array — 当前要使用的MongoDB配置, [配置名,db名,collection名]

$config

$config : array

Type

array — 全局MongoDB配置

$mongoClient

$mongoClient : \MongoClient

Type

\MongoClient — MongoDB Client实例

$mongoDb

$mongoDb : \MongoDB

Type

\MongoDB — MongoDB实例

$mongoCollection

$mongoCollection : \MongoCollection

Type

\MongoCollection — MongoCollection实例

$taskProxyData

$taskProxyData : mixed

Type

mixed — task执行数据

$profileName

$profileName : string

Type

string — 性能分析name

Methods

__construct()

__construct() 

构造方法

Throws

\MongoConnectionException

__initialization()

__initialization(integer  $taskId, integer  $workerPid, string  $taskName, string  $methodName, \PG\MSF\Helpers\Context  $context, \PG\AOP\Wrapper|\PG\MSF\Base\Pool  $objectPool) 

Tasker进程中初始化任务

Parameters

integer $taskId

Task ID

integer $workerPid

worker pid

string $taskName

任务类名

string $methodName

任务类方法

\PG\MSF\Helpers\Context $context

请求上下文对象

\PG\AOP\Wrapper|\PG\MSF\Base\Pool $objectPool

对象池对象

destroy()

destroy() 

销毁,解除引用

__call()

__call(string  $name, array  $arguments) : \PG\MSF\Coroutine\CTask

__call魔术方法

Parameters

string $name

任务方法名

array $arguments

执行参数

Returns

\PG\MSF\Coroutine\CTask

setTimeout()

setTimeout(integer  $timeout) : $this

设置任务执行超时时间

Parameters

integer $timeout

超时时间,单位毫秒

Returns

$this

getTimeout()

getTimeout() : integer

获取任务执行超时时间

Returns

integer

startTask()

startTask(callable|null  $callback = null) 

异步任务

Parameters

callable|null $callback

任务执行完成的回调

__sleep()

__sleep() : array

在序列化及dump对象时使用,代表哪些属于需要导出

Returns

array

__unsleep()

__unsleep() 

和__sleep作用相反

getServerInstance()

getServerInstance() : \swoole_server

获取运行Server实例

Returns

\swoole_server

getConfig()

getConfig() : \Noodlehaus\Config

获取运行server实例配置对象

Returns

\Noodlehaus\Config

getPack()

getPack() : \PG\MSF\Pack\IPack

获取运行server实例打包对象

Returns

\PG\MSF\Pack\IPack

getRedisPool()

getRedisPool(string  $poolName) : boolean|\PG\AOP\Wrapper|\PG\MSF\Pools\CoroutineRedisProxy|\Redis

获取Redis连接池

Parameters

string $poolName

配置的Redis连接池名称

Returns

boolean|\PG\AOP\Wrapper|\PG\MSF\Pools\CoroutineRedisProxy|\Redis

getMysqlPool()

getMysqlPool(string  $poolName) : boolean|\PG\AOP\Wrapper

获取MySQL连接池

Parameters

string $poolName

配置的MySQL连接池名称

Returns

boolean|\PG\AOP\Wrapper

getRedisProxy()

getRedisProxy(string  $proxyName) : boolean|\PG\AOP\Wrapper|\PG\MSF\Pools\CoroutineRedisProxy|\Redis

获取Redis代理

Parameters

string $proxyName

配置的Redis代理名称

Throws

\Exception

Returns

boolean|\PG\AOP\Wrapper|\PG\MSF\Pools\CoroutineRedisProxy|\Redis

setRedisPools()

setRedisPools(array|null  $redisPools) : $this

设置RedisPools

Parameters

array|null $redisPools

多个Redis连接池实例,通常用于销毁Redis连接池,赋值为NULL

Returns

$this

setRedisProxies()

setRedisProxies(array|null  $redisProxies) : $this

设置RedisPools

Parameters

array|null $redisProxies

多个Redis代理实例,通常用于销毁Redis代理,赋值为NULL

Returns

$this

isUse()

isUse() 

对象已使用标识

getIsDestroy()

getIsDestroy() : boolean

是否已经执行destroy

Returns

boolean

setContext()

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

设置上下文

Parameters

\PG\MSF\Helpers\Context $context

请求上下文对象

Returns

$this

setDbCollection()

setDbCollection(string  $dbName, string  $collectionName) : \MongoCollection

独立选择DB和collection

Parameters

string $dbName

MongoDB Name

string $collectionName

MongoDB Collection Name

Returns

\MongoCollection

prepare()

prepare(string  $confKey, string  $db, string  $collection) 

初始化链接 每个task进程内只初始化一次

Parameters

string $confKey

配置名称

string $db

MongoDB Name

string $collection

MongoDB Collection Name

Throws

\MongoConnectionException

query()

query(array  $query = array(), array  $fields = array(), array  $sort = null, integer  $limit = null, integer  $skip = null, integer  $timeout = 2000) : \PG\MSF\Tasks\array:

查询文档,返回二维数组的数据

Parameters

array $query

查询条件,如:['_id' => new \MongoId('0f6821586b9887e3174e7c78')]

array $fields

返回的字段列表,默认全部,如:['name' => true, 'age' => true]

array $sort

排序,如:['create_time' => 1, '_id' => -1]

integer $limit

限制返回的数据文档数

integer $skip

开始返回的offset

integer $timeout

查询超时时间,default 2s, 0 wait forever.

Returns

\PG\MSF\Tasks\array:

findOne()

findOne(array  $query = array(), array  $fields = array(), integer  $timeout = 2000) : array|null

查询返回一条数据

Parameters

array $query

查询条件,如:['_id' => new \MongoId('0f6821586b9887e3174e7c78')]

array $fields

返回的字段列表,默认全部,如:['name' => true, 'age' => true]

integer $timeout

查询超时时间,default 2s, 0 wait forever.

Returns

array|null

count()

count(array  $query = array(), integer|null  $limit = null, integer|null  $skip = null, integer  $timeout = 2000) : integer

返回符合条件的文档数

Parameters

array $query

查询条件,如:['_id' => new \MongoId('0f6821586b9887e3174e7c78')]

integer|null $limit

限制返回的数据文档数

integer|null $skip

开始查询的offset

integer $timeout

查询超时时间,default 2s, 0 wait forever.

Returns

integer

add()

add(array  $doc, integer  $timeout = 2000, integer  $w = 1, boolean  $fsync = false) : boolean

新建文档

Parameters

array $doc

待创建的文档数据

integer $timeout

查询超时时间,default 2s, 0 wait forever.

integer $w

http://php.net/manual/zh/mongo.writeconcerns.php

boolean $fsync

是否立即写入磁盘

Returns

boolean

batchAdd()

batchAdd(array  $docs, boolean  $continueOnError = true, integer  $timeout = 2000, integer  $w = 1, boolean  $fsync = false) : boolean

批量新建文档

Parameters

array $docs

新建文档的二维数组

boolean $continueOnError

出现错误是否继续插入

integer $timeout

查询超时时间,default 2s, 0 wait forever.

integer $w

http://php.net/manual/zh/mongo.writeconcerns.php

boolean $fsync

是否立即写入磁盘

Returns

boolean

modify()

modify(array  $criteria, array  $doc, boolean  $multiple = true, boolean  $upsert = false, integer  $timeout = 2000, integer  $w = 1, boolean  $fsync = false) : boolean

修改文档(包含set关键字)

Parameters

array $criteria

更新条件

array $doc

要更新的字段和值

boolean $multiple

是否更新所有符合条件的文档

boolean $upsert

没有符合条件的文档时,是否插入新文档

integer $timeout

超时时间,单位ms

integer $w

成功写入到多少个复制时返回

boolean $fsync

是否等待MongoDB将数据更新到磁盘

Returns

boolean

updateDoc()

updateDoc(array  $criteria, array  $doc, boolean  $multiple = true, boolean  $upsert = false, integer  $timeout = 2000, integer  $w = 1, boolean  $fsync = false) : boolean

修改文档

Parameters

array $criteria

更新条件

array $doc

要更新的字段和值

boolean $multiple

是否更新所有符合条件的文档

boolean $upsert

没有符合条件的文档时,是否插入新文档

integer $timeout

超时时间,单位ms

integer $w

成功写入到多少个复制时返回

boolean $fsync

是否等待MongoDB将数据更新到磁盘

Returns

boolean

delete()

delete(array  $criteria, boolean  $justOne = false, integer  $timeout = 5000, integer  $w = 1, boolean  $fsync = false) : boolean

删除文档

Parameters

array $criteria

删除条件

boolean $justOne

是否只删除符合条件的第一条

integer $timeout

超时时间,单位ms

integer $w

成功写入到多少个复制时返回

boolean $fsync

是否等待MongoDB将数据更新到磁盘

Returns

boolean

command()

command(  $command, integer  $timeout = 5000) : boolean

对当前Collection所在Database上执行command

Parameters

$command
integer $timeout

超时时间,单位ms

Returns

boolean