phpday 2027 - Call for Papers

Io\Poll\Context::__construct

(PHP 8 >= 8.6.0)

Io\Poll\Context::__construct — Creates a polling context

说明

public function Io\Poll\Context::__construct(Io\Poll\Backend $backend = Io\Poll\Backend::Auto)

Creates a polling context that uses the given backend.

参数

backend

The polling mechanism to use. With Io\Poll\Backend::Auto, the most suitable backend available on the platform is selected; Io\Poll\Context::getBackend() tells which one it is.

错误/异常

Throws an Io\Poll\BackendUnavailableException if backend is not available on the platform.

Throws an Io\Poll\FailedContextInitializationException if the backend cannot be initialized.

示例

示例 #1 Io\Poll\Context::__construct() example

<?php
use Io\Poll\Backend;
use Io\Poll\BackendUnavailableException;
use Io\Poll\Context;

$context = new Context();
var_dump($context->getBackend());

try {
    $context = new Context(Backend::WSAPoll);
} catch (BackendUnavailableException $exception) {
    echo $exception->getMessage(), PHP_EOL;
}

以上示例的输出类似于:

enum(Io\Poll\Backend::Epoll)
Backend WSAPoll not available

参见

+添加备注

用户贡献的备注

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