From 2f85e8eeffc6c4977a8688e7faab73022cb02db3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Mon, 23 Dec 2019 22:13:32 +0100 Subject: [PATCH 1/3] Fix unsupported EventConfig for ext-event on Windows --- .travis.yml | 14 ++++++++++++++ src/ExtEventLoop.php | 10 +++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3329ead7..7182febc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,6 +37,20 @@ matrix: - export PATH="$(powershell -Command '("Process", "Machine" | % { [Environment]::GetEnvironmentVariable("PATH", $_) -Split ";" -Replace "\\$", "" } | Select -Unique | % { cygpath $_ }) -Join ":"')" install: - composer install + - name: "Windows PHP 7.2 with ext-event" + os: windows + language: shell # no built-in php support + before_install: + - curl -OL https://windows.php.net/downloads/pecl/releases/event/2.5.3/php_event-2.5.3-7.2-nts-vc15-x64.zip # latest version as of 2019-12-23 + - choco install php --version=7.2.26 # latest version supported by ext-event as of 2019-12-23 + - choco install composer + - export PATH="$(powershell -Command '("Process", "Machine" | % { [Environment]::GetEnvironmentVariable("PATH", $_) -Split ";" -Replace "\\$", "" } | Select -Unique | % { cygpath $_ }) -Join ":"')" + - php -r "\$z=new ZipArchive();\$z->open(glob('php_event*.zip')[0]);\$z->extractTo(dirname(php_ini_loaded_file()).'/ext','php_event.dll');" + - php -r "file_put_contents(php_ini_loaded_file(),'extension_dir=ext'.PHP_EOL,FILE_APPEND);" + - php -r "file_put_contents(php_ini_loaded_file(),'extension=sockets'.PHP_EOL,FILE_APPEND);" # ext-sockets needs to be loaded before ext-event + - php -r "file_put_contents(php_ini_loaded_file(),'extension=event'.PHP_EOL,FILE_APPEND);" + install: + - composer install allow_failures: - php: hhvm - os: windows diff --git a/src/ExtEventLoop.php b/src/ExtEventLoop.php index fd403d4a..fdf6d5fa 100644 --- a/src/ExtEventLoop.php +++ b/src/ExtEventLoop.php @@ -5,7 +5,6 @@ use BadMethodCallException; use Event; use EventBase; -use EventConfig as EventBaseConfig; use React\EventLoop\Tick\FutureTickQueue; use React\EventLoop\Timer\Timer; use SplObjectStorage; @@ -43,8 +42,13 @@ public function __construct() throw new BadMethodCallException('Cannot create ExtEventLoop, ext-event extension missing'); } - $config = new EventBaseConfig(); - $config->requireFeatures(EventBaseConfig::FEATURE_FDS); + // support arbitrary file descriptors and not just sockets + // Windows only has limited file descriptor support, so do not require this (will fail otherwise) + // @link http://www.wangafu.net/~nickm/libevent-book/Ref2_eventbase.html#_setting_up_a_complicated_event_base + $config = new \EventConfig(); + if (\DIRECTORY_SEPARATOR !== '\\') { + $config->requireFeatures(\EventConfig::FEATURE_FDS); + } $this->eventBase = new EventBase($config); $this->futureTickQueue = new FutureTickQueue(); From 47ab46ffe61a2d817df828b04892542efdc1be0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Fri, 27 Dec 2019 20:38:25 +0100 Subject: [PATCH 2/3] Ignore unrelated SEGFAULT when all tests pass for ext-event on Windows --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 7182febc..944d6ba2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,6 +51,8 @@ matrix: - php -r "file_put_contents(php_ini_loaded_file(),'extension=event'.PHP_EOL,FILE_APPEND);" install: - composer install + script: + - vendor/bin/phpunit --coverage-text || ([[ $? = 139 ]] && echo && echo "Ignoring SEGFAULT.." >&2) # ignore unrelated SEGFAULT when all tests pass allow_failures: - php: hhvm - os: windows From 3698022d03d8adc964e696d884b6519aad5d8a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Fri, 27 Dec 2019 21:24:25 +0100 Subject: [PATCH 3/3] Avoid SEGFAULTs for ext-event on Windows by clearing all Event refs --- .travis.yml | 2 -- src/ExtEventLoop.php | 11 +++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 944d6ba2..7182febc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,8 +51,6 @@ matrix: - php -r "file_put_contents(php_ini_loaded_file(),'extension=event'.PHP_EOL,FILE_APPEND);" install: - composer install - script: - - vendor/bin/phpunit --coverage-text || ([[ $? = 139 ]] && echo && echo "Ignoring SEGFAULT.." >&2) # ignore unrelated SEGFAULT when all tests pass allow_failures: - php: hhvm - os: windows diff --git a/src/ExtEventLoop.php b/src/ExtEventLoop.php index fdf6d5fa..1f1b9ea4 100644 --- a/src/ExtEventLoop.php +++ b/src/ExtEventLoop.php @@ -59,6 +59,17 @@ public function __construct() $this->createStreamCallback(); } + public function __destruct() + { + // explicitly clear all references to Event objects to prevent SEGFAULTs on Windows + foreach ($this->timerEvents as $timer) { + $this->timerEvents->detach($timer); + } + + $this->readEvents = array(); + $this->writeEvents = array(); + } + public function addReadStream($stream, $listener) { $key = (int) $stream;