diff --git a/README.md b/README.md index 7a30ec15..5ee4d8e5 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,7 @@ You should use the [`Factory`](#factory) to automatically create a new instance. Advanced! If you explicitly need a certain event loop implementation, you can manually instantiate one of the following classes. Note that you may have to install the required PHP extensions for the respective -event loop implementation first or this may result in a fatal error. +event loop implementation first or they will throw a `BadMethodCallException` on creation. #### StreamSelectLoop diff --git a/src/ExtEventLoop.php b/src/ExtEventLoop.php index 4582a38a..622dd472 100644 --- a/src/ExtEventLoop.php +++ b/src/ExtEventLoop.php @@ -2,6 +2,7 @@ namespace React\EventLoop; +use BadMethodCallException; use Event; use EventBase; use EventConfig as EventBaseConfig; @@ -38,6 +39,10 @@ final class ExtEventLoop implements LoopInterface public function __construct() { + if (!class_exists('EventBase', false)) { + throw new BadMethodCallException('Cannot create ExtEventLoop, ext-event extension missing'); + } + $config = new EventBaseConfig(); $config->requireFeatures(EventBaseConfig::FEATURE_FDS); diff --git a/src/ExtLibevLoop.php b/src/ExtLibevLoop.php index 9c679895..d3b0df81 100644 --- a/src/ExtLibevLoop.php +++ b/src/ExtLibevLoop.php @@ -2,6 +2,7 @@ namespace React\EventLoop; +use BadMethodCallException; use libev\EventLoop; use libev\IOEvent; use libev\SignalEvent; @@ -36,6 +37,10 @@ final class ExtLibevLoop implements LoopInterface public function __construct() { + if (!class_exists('libev\EventLoop', false)) { + throw new BadMethodCallException('Cannot create ExtLibevLoop, ext-libev extension missing'); + } + $this->loop = new EventLoop(); $this->futureTickQueue = new FutureTickQueue(); $this->timerEvents = new SplObjectStorage(); diff --git a/src/ExtLibeventLoop.php b/src/ExtLibeventLoop.php index 5bc265e2..427f8db0 100644 --- a/src/ExtLibeventLoop.php +++ b/src/ExtLibeventLoop.php @@ -2,6 +2,7 @@ namespace React\EventLoop; +use BadMethodCallException; use Event; use EventBase; use React\EventLoop\Tick\FutureTickQueue; @@ -52,6 +53,10 @@ final class ExtLibeventLoop implements LoopInterface public function __construct() { + if (!function_exists('event_base_new')) { + throw new BadMethodCallException('Cannot create ExtLibeventLoop, ext-libevent extension missing'); + } + $this->eventBase = event_base_new(); $this->futureTickQueue = new FutureTickQueue(); $this->timerEvents = new SplObjectStorage();
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: