Skip to content

Commit 1d8055f

Browse files
authored
Merge pull request #205 from clue-labs/ext-event-windows
Fix unsupported EventConfig and SEGFAULTs on shutdown for ext-event on Windows
2 parents 20bbe7d + 3698022 commit 1d8055f

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ matrix:
3737
- export PATH="$(powershell -Command '("Process", "Machine" | % { [Environment]::GetEnvironmentVariable("PATH", $_) -Split ";" -Replace "\\$", "" } | Select -Unique | % { cygpath $_ }) -Join ":"')"
3838
install:
3939
- composer install
40+
- name: "Windows PHP 7.2 with ext-event"
41+
os: windows
42+
language: shell # no built-in php support
43+
before_install:
44+
- 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
45+
- choco install php --version=7.2.26 # latest version supported by ext-event as of 2019-12-23
46+
- choco install composer
47+
- export PATH="$(powershell -Command '("Process", "Machine" | % { [Environment]::GetEnvironmentVariable("PATH", $_) -Split ";" -Replace "\\$", "" } | Select -Unique | % { cygpath $_ }) -Join ":"')"
48+
- php -r "\$z=new ZipArchive();\$z->open(glob('php_event*.zip')[0]);\$z->extractTo(dirname(php_ini_loaded_file()).'/ext','php_event.dll');"
49+
- php -r "file_put_contents(php_ini_loaded_file(),'extension_dir=ext'.PHP_EOL,FILE_APPEND);"
50+
- php -r "file_put_contents(php_ini_loaded_file(),'extension=sockets'.PHP_EOL,FILE_APPEND);" # ext-sockets needs to be loaded before ext-event
51+
- php -r "file_put_contents(php_ini_loaded_file(),'extension=event'.PHP_EOL,FILE_APPEND);"
52+
install:
53+
- composer install
4054
allow_failures:
4155
- php: hhvm
4256
- os: windows

src/ExtEventLoop.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use BadMethodCallException;
66
use Event;
77
use EventBase;
8-
use EventConfig as EventBaseConfig;
98
use React\EventLoop\Tick\FutureTickQueue;
109
use React\EventLoop\Timer\Timer;
1110
use SplObjectStorage;
@@ -43,8 +42,13 @@ public function __construct()
4342
throw new BadMethodCallException('Cannot create ExtEventLoop, ext-event extension missing');
4443
}
4544

46-
$config = new EventBaseConfig();
47-
$config->requireFeatures(EventBaseConfig::FEATURE_FDS);
45+
// support arbitrary file descriptors and not just sockets
46+
// Windows only has limited file descriptor support, so do not require this (will fail otherwise)
47+
// @link http://www.wangafu.net/~nickm/libevent-book/Ref2_eventbase.html#_setting_up_a_complicated_event_base
48+
$config = new \EventConfig();
49+
if (\DIRECTORY_SEPARATOR !== '\\') {
50+
$config->requireFeatures(\EventConfig::FEATURE_FDS);
51+
}
4852

4953
$this->eventBase = new EventBase($config);
5054
$this->futureTickQueue = new FutureTickQueue();
@@ -55,6 +59,17 @@ public function __construct()
5559
$this->createStreamCallback();
5660
}
5761

62+
public function __destruct()
63+
{
64+
// explicitly clear all references to Event objects to prevent SEGFAULTs on Windows
65+
foreach ($this->timerEvents as $timer) {
66+
$this->timerEvents->detach($timer);
67+
}
68+
69+
$this->readEvents = array();
70+
$this->writeEvents = array();
71+
}
72+
5873
public function addReadStream($stream, $listener)
5974
{
6075
$key = (int) $stream;

0 commit comments

Comments
 (0)