1
0
mirror of https://github.com/danog/amp.git synced 2025-01-19 03:44:47 +01:00

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.
This commit is contained in:
Douglas G.R 2015-01-06 00:01:07 -02:00
parent b1ffd3c918
commit cf3e13a595
3 changed files with 12 additions and 0 deletions

View File

@ -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",

View File

@ -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']);

View File

@ -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(); };