Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5
<?php OpenSwoole\Coroutine\Channel->stats(): array
The number of consumers, 0 indicates that the current channel is empty, more than 0 means a coroutine(s) is waiting for other coroutine to call push()
for addition of data to the channel.
Number of producers, if this number is the same as the channel capacity, it indicates the current channel is full, there is a coroutine(s) waiting for other coroutine(s) to pop()
to take data out of the channel, allowing data to be pushed on again.
Current number of elements in the channel.
Since Open Swoole v4.10.0, the ID of the channel is included in stats
Get the stats of the Channel.
<?php
co::run(function() {
$data = 'Hello World!';
$chan = new chan(1);
$chan->push($data);
var_dump($chan->stats());
});
The above will show:
[
"id" => 1,
"consumer_num" => 0,
"producer_num" => 1,
"queue_num" => 1
]