\Imi\UtilChannelManager

通道队列类-支持多进程

Summary

Methods
Properties
Constants
init()
addName()
setNames()
getNames()
getInstance()
push()
pop()
stats()
No public properties found
No constants found
No protected methods found
$isInited
$channels
N/A
No private methods found
No private properties found
N/A

Properties

$isInited

$isInited : boolean

是否已初始化过

Type

boolean

$channels

$channels : array<mixed,\Swoole\Channel>

\Swoole\Channel 数组

Type

array<mixed,\Swoole\Channel>

Methods

init()

init() : void

初始化

addName()

addName(string  $name, integer  $size) : void

增加对象名称

Parameters

string $name
integer $size

通道占用的内存的尺寸,单位为字节。最小值为64K,最大值没有限制

setNames()

setNames(array<mixed,string>  $names) : void

设置对象名称

Parameters

array<mixed,string> $names

getNames()

getNames() : void

获取所有对象名称

getInstance()

getInstance(string  $name) : \Swoole\Atomic

获取实例

Parameters

string $name

Returns

\Swoole\Atomic

push()

push(string  $name, mixed  $data) : boolean

向通道写入数据 $data可以为任意PHP变量,当$data是非字符串类型时底层会自动进行串化 $data的尺寸超过8K时会启用临时文件存储数据 $data必须为非空变量,如空字符串、空数组、0、null、false 写入成功返回true 通道的空间不足时写入失败并返回false

Parameters

string $name
mixed $data

Returns

boolean

pop()

pop(string  $name) : mixed

弹出数据 pop方法无需传入任何参数 当通道内有数据时自动将数据弹出并还原为PHP变量 当通道内没有任何数据时pop会失败并返回false

Parameters

string $name

Returns

mixed

stats()

stats(string  $name) : array

获取通道的状态 返回一个数组,包括2项信息 queue_num 通道中的元素数量 queue_bytes 通道当前占用的内存字节数

Parameters

string $name

Returns

array