phpday 2027 - Call for Papers

StreamPollHandle::isValid

(PHP 8 >= 8.6.0)

StreamPollHandle::isValid — Checks whether the stream is open and not at end-of-file

说明

public function StreamPollHandle::isValid(): bool

Checks whether the stream of the handle is still open and has not reached its end.

参数

此函数没有参数。

返回值

Returns true if the stream is open and not at end-of-file, false otherwise.

示例

示例 #1 StreamPollHandle::isValid() example

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

$handle = new StreamPollHandle($reader);
var_dump($handle->isValid());

// The other end is closed, so the stream reaches its end.
fclose($writer);
var_dump($handle->isValid());

fclose($reader);
var_dump($handle->isValid());

以上示例会输出:

bool(true)
bool(false)
bool(false)

参见

  • Io\Poll\Watcher::isActive()
  • feof() - 测试文件指针是否到了文件结束的位置
+添加备注

用户贡献的备注

此页面尚无用户贡献的备注。
To Top