Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Get string length
<?php strlen(string $string): int
<?php     $connection->once('data', function () use ($connection) {

        $body = "<html><h1>Hello world!</h1></html>\r\n";

        $connection->end("HTTP/1.1 200 OK\r\nContent-Length: " . strlen($body) . "\r\nConnection: close\r\n\r\n" . $body);

    });



    $connection->on('close', function () use ($connection) {
<?php     $bytes = 0;

    $connection->on('data', function ($chunk) use (&$bytes) {

        $bytes += strlen($chunk);

    });
<?php         }



        $this->assertNotFalse(inet_pton($ip));

        $this->assertEquals(4, strlen(inet_pton($ip)));

    }
<?php         }



        $this->assertNotFalse(inet_pton($ip));

        $this->assertEquals(16, strlen(inet_pton($ip)));

    }



    public function testCancelPendingTlsConnectionDuringTlsHandshakeShouldCloseTcpConnectionToServer()
<?php             $connecting->then(function (ConnectionInterface $connection) use ($resolve) {

                $received = 0;

                $connection->on('data', function ($chunk) use (&$received, $resolve, $connection) {

                    $received += strlen($chunk);



                    if ($received >= 400000) {

                        $resolve($received);
<?php             $connecting->then(function (ConnectionInterface $connection) use ($resolve) {

                $received = 0;

                $connection->on('data', function ($chunk) use (&$received, $resolve) {

                    $received += strlen($chunk);



                    if ($received >= 2000000) {

                        $resolve($received);
<?php             $server->on('connection', function (ConnectionInterface $connection) use ($resolve) {

                $received = 0;

                $connection->on('data', function ($chunk) use (&$received, $resolve) {

                    $received += strlen($chunk);



                    if ($received >= 400000) {

                        $resolve($received);
<?php             $connecting->then(function (ConnectionInterface $connection) use ($resolve) {

                $received = 0;

                $connection->on('data', function ($chunk) use (&$received, $resolve) {

                    $received += strlen($chunk);



                    if ($received >= 400000) {

                        $resolve($received);
<?php         $received = Block\await($disconnected->promise(), null, self::TIMEOUT);



        $this->assertEquals(strlen($data), strlen($received));

        $this->assertEquals($data, $received);

    }
<?php                 $connection->on('data', function ($chunk) use (&$received, $resolve) {

                    $received .= $chunk;



                    if (strlen($received) >= 200000) {

                        $resolve($received);

                    }

                });
<?php         $received = Block\await($promise, null, self::TIMEOUT);



        $this->assertEquals(strlen($data), strlen($received));

        $this->assertEquals($data, $received);



        $connecting->then(function (ConnectionInterface $connection) {
<?php             $connecting->then(function (ConnectionInterface $connection) use ($resolve) {

                $received = 0;

                $connection->on('data', function ($chunk) use (&$received, $resolve) {

                    $received += strlen($chunk);



                    if ($received >= 100000) {

                        $resolve($received);
<?php         $received = Block\await($promise, null, self::TIMEOUT);



        $this->assertEquals(strlen($data), $received);



        $connecting->then(function (ConnectionInterface $connection) {

            $connection->close();
<?php         $server->on('connection', function ($conn) use ($mock, &$received, $server) {


            $conn->on('data', function ($data) use (&$received) {

                $received += strlen($data);

            });



            $conn->on('end', $mock);
<?php         $server->on('connection', function ($conn) use ($mock, &$received, $server) {


            $conn->on('data', function ($data) use (&$received) {

                $received += strlen($data);

            });



            $conn->on('end', $mock);