From cf3e13a595ab56c2429108b01eff70d388a83136 Mon Sep 17 00:00:00 2001 From: "Douglas G.R" Date: Tue, 6 Jan 2015 00:01:07 -0200 Subject: [PATCH] Throws a RuntimeException if php-uv or libevent is not loaded. Using UvReactor or LibeventReactor directly (instead of Amp\getReactor) doesn't check if php-uv/libevent is loaded and dies with a 'Call to undefined function' message. --- composer.json | 4 ++++ lib/LibeventReactor.php | 4 ++++ lib/UvReactor.php | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/composer.json b/composer.json index 32393f9..73e44c1 100644 --- a/composer.json +++ b/composer.json @@ -38,6 +38,10 @@ "dev-master": "1.0.x-dev" } }, + "suggest": { + "php-uv": "Extension for libuv backends (high performance use cases).", + "pecl/libevent": "Extension for libevent backends (high performance use cases)." + }, "repositories": [ { "type": "vcs", diff --git a/lib/LibeventReactor.php b/lib/LibeventReactor.php index e9ab754..27ba103 100644 --- a/lib/LibeventReactor.php +++ b/lib/LibeventReactor.php @@ -22,6 +22,10 @@ class LibeventReactor implements SignalReactor { private static $instanceCount = 0; public function __construct() { + if (!extension_loaded('libevent')) { + throw new \RuntimeException('The pecl-libevent extension is required to use the LibeventReactor.'); + } + $this->base = event_base_new(); $this->gcEvent = event_new(); event_timer_set($this->gcEvent, [$this, 'collectGarbage']); diff --git a/lib/UvReactor.php b/lib/UvReactor.php index 2d68d9b..cd67256 100644 --- a/lib/UvReactor.php +++ b/lib/UvReactor.php @@ -25,6 +25,10 @@ class UvReactor implements SignalReactor { private static $instanceCount = 0; public function __construct() { + if (!extension_loaded('uv')) { + throw new \RuntimeException('The php-uv extension is required to use the UvReactor.'); + } + $this->loop = uv_loop_new(); $this->gcWatcher = uv_timer_init($this->loop); $this->gcCallback = function() { $this->collectGarbage(); };