Swoole\Coroutine\Channel->stats()

Latest version: pecl install openswoole-4.11.1

Declaration

<?php Swoole\Coroutine\Channel->stats(): array

Parameters

None

Return

Returns an array of the following:
consumer_num

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.

producer_num

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.

queue_num

Current number of elements in the channel.

Swoole Coroutine Channel Stats

Description

Since Open Swoole v4.10.0, the ID of the channel is included in stats

Get the stats of the Channel.

Example

<?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
]
Last updated on March 31, 2022