helpers.php
Table of Contents
Functions
- publish() : int|null
- 生产
- action() : mixed
- 复用连接进行多次操作
- is_empty_dir() : bool
- binary_dump() : string
- produce a hex+ASCII dump of a binary string.
Functions
publish()
生产
publish(AbstractBuilder $builder, string $body[, string|null $routingKey = null ][, array<string|int, mixed>|null $headers = null ][, ConnectionInterface|null $connection = null ]) : int|null
Parameters
- $builder : AbstractBuilder
- $body : string
- $routingKey : string|null = null
- $headers : array<string|int, mixed>|null = null
- $connection : ConnectionInterface|null = null
-
传入已有连接可跳过池借还,适合 consumer 内高频调用
Return values
int|nullaction()
复用连接进行多次操作
action(callable(ConnectionInterface): mixed $callback[, string $connection = 'default' ]) : mixed
从连接池借一个连接,执行回调后自动归还。 适合高频 publish 场景,避免每次 publish() 都单独借还连接。
// consumer handler 中复用同一个连接
action(function (ConnectionInterface $connection) use ($builder, $a, $b) {
publish($builder, $a, connection: $connection);
publish($builder, $b, connection: $connection);
});
Parameters
- $callback : callable(ConnectionInterface): mixed
- $connection : string = 'default'
is_empty_dir()
is_empty_dir(string $path[, bool $remove = false ]) : bool
Parameters
- $path : string
- $remove : bool = false
Return values
boolbinary_dump()
produce a hex+ASCII dump of a binary string.
binary_dump(string $binary[, int $bytesPerLine = 16 ][, bool $showAscii = true ][, bool $uppercase = true ]) : string
Parameters
- $binary : string
-
Binary input string to dump.
- $bytesPerLine : int = 16
-
Number of bytes to show per line (default 16).
- $showAscii : bool = true
-
Whether to include the ASCII column (default true).
- $uppercase : bool = true
-
Whether hex letters are uppercase (default true).
Return values
string —Formatted multi-line hex dump.