OpenSwoole\Coroutine\Http2\Client->stats(...)

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

Declaration

<?php OpenSwoole\Coroutine\Http2\Client->stats(string $key = null): array|bool

Parameters

key

Used to return only a certain array element index at the first level.

Return

An array if no key is given, if a key is given it will either be an array if the key was found or null if the key is not found.


Description

Get the stream status. Returns an array of information about the current streams, see example below for details of what information is given.


Example

<?php

use OpenSwoole\Coroutine\Http2\Client;

co::run(function()
{
    $client = new OpenSwoole\Coroutine\Http2\Client('127.0.0.1', 9518);

    var_dump($client->stats('remote_settings'));
});

The above example will output something similar to:

<?php

array(5) {
  ["current_stream_id"]=>
  int(0)
  ["last_stream_id"]=>
  int(0)
  ["local_settings"]=>
  array(5) {
    ["header_table_size"]=>
    int(4096)
    ["window_size"]=>
    int(65535)

    ["max_concurrent_streams"]=>
    int(128)
    ["max_frame_size"]=>
    int(16384)
    ["max_header_list_size"]=>
    int(4096)
  }
  ["remote_settings"]=>
  array(5) {
    ["header_table_size"]=>
    int(0)
    ["window_size"]=>
    int(0)
    ["max_concurrent_streams"]=>
    int(0)
    ["max_frame_size"]=>
    int(0)
    ["max_header_list_size"]=>
    int(0)
  }
  ["active_stream_num"]=>
  int(0)
}

The stats function has a $key parameter so you can choose to only return a certain array index but this is only at the first level. To return deeper array elements you could do something like:

<?php

$client = new OpenSwoole\Coroutine\Http2\Client('127.0.0.1', 9518);
var_dump($client->stats()['remote_settings']['header_table_size']);
Last updated on September 1, 2022