Skip to content

Commit 371f3a5

Browse files
committed
Fix Swow first request hang on Windows
1 parent ad9546a commit 371f3a5

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

src/Events/Select.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,6 @@ protected function setNextTickTime(float $nextTickTime): void
364364
{
365365
$this->nextTickTime = $nextTickTime;
366366
if ($nextTickTime == 0) {
367-
// Swow will affect the signal interruption characteristics of stream_select,
368-
// so a shorter timeout should be used to detect signals.
369367
$this->selectTimeout = self::MAX_SELECT_TIMOUT_US;
370368
return;
371369
}

src/Events/Swow.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ public function onReadable($stream, callable $func): void
144144
}
145145
// Under Windows, setting a timeout is necessary; otherwise, the accept cannot be listened to.
146146
// Setting it to 1000ms will result in a 1-second delay for the first accept under Windows.
147-
$rEvent = stream_poll_one($stream, STREAM_POLLIN | STREAM_POLLHUP, 1000);
148147
if (!isset($this->readEvents[$fd]) || $this->readEvents[$fd] !== Coroutine::getCurrent()) {
149148
break;
150149
}
150+
$rEvent = stream_poll_one($stream, STREAM_POLLIN | STREAM_POLLHUP, 1000);
151151
if ($rEvent !== STREAM_POLLNONE) {
152152
$this->safeCall($func, [$stream]);
153153
}

src/Worker.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Worker
6161
*
6262
* @var string
6363
*/
64-
final public const VERSION = '5.1.2';
64+
final public const VERSION = '5.1.3';
6565

6666
/**
6767
* Status initial.
@@ -1594,7 +1594,17 @@ protected static function forkWorkersForWindows(): void
15941594
restore_error_handler();
15951595

15961596
// Add an empty timer to prevent the event-loop from exiting.
1597-
Timer::add(1000000, function (){});
1597+
Timer::add(0.8, function (){});
1598+
1599+
// Compatibility with the bug in Swow where the first request on Windows fails to trigger stream_select.
1600+
if (extension_loaded('swow')) {
1601+
Timer::delay(0.1 , function(){
1602+
$stream = fopen(__FILE__, 'r');
1603+
static::$globalEvent->onReadable($stream, function($stream) {
1604+
static::$globalEvent->offReadable($stream);
1605+
});
1606+
});
1607+
}
15981608

15991609
// Display UI.
16001610
static::safeEcho(str_pad($worker->name, 48) . str_pad($worker->getSocketName(), 36) . str_pad('1', 10) . " [ok]\n");

0 commit comments

Comments
 (0)