Swoole\Coroutine\Channel->stats()

Swoole Coroutine Channel Stats

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.

Description

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:

[
  "consumer_num" => 0,
  "producer_num" => 1,
  "queue_num" => 1
]