Io\Poll\Context::__construct
Creates a polling context
Description
public Io\Poll\Context::__construct(Io\Poll\Backend $backend = Io\Poll\Backend::Auto)
Creates a polling context that uses the given
backend.
Parameters
-
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.
Errors/Exceptions
Throws an
Io\Poll\BackendUnavailableException if
backend is not available on the platform.
Throws an
Io\Poll\FailedContextInitializationException
if the backend cannot be initialized.
Examples
Example #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;
}
The above example will output
something similar to:
enum(Io\Poll\Backend::Epoll)
Backend WSAPoll not available
See Also
- Io\Poll\Context::getBackend
- Io\Poll\Backend::getAvailableBackends
- Io\Poll\Backend::isAvailable