phpday 2027 - Call for Papers

StreamPollHandle::__construct

(PHP 8 >= 8.6.0)

StreamPollHandle::__construct — Creates a poll handle for a stream

Descrição

public function StreamPollHandle::__construct(resource $stream)

Creates a handle that allows stream to be watched by an Io\Poll\Context. The handle holds a reference to the stream, which therefore stays open until fclose() is called on it.

Parâmetros

stream

An open stream, such as a socket created with stream_socket_client() or stream_socket_accept().

Erros/Exceções

Throws a TypeError if stream is not an open stream.

Exemplos

Exemplo #1 StreamPollHandle::__construct() example

<?php
use Io\Poll\Context;
use Io\Poll\Event;

[$reader, $writer] = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);

$handle = new StreamPollHandle($reader);

$context = new Context();
$watcher = $context->add($handle, [Event::Read]);
var_dump($watcher->isActive());

O exemplo acima produzirá:

bool(true)

Veja também

+adicionar nota

Notas de Usuários

Não há notas de usuários para esta página.
To Top