Skip to content

Commit

Permalink
Fix #5558
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Nov 8, 2024
1 parent a38920d commit bd6bba4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ext-src/swoole_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3865,14 +3865,16 @@ static PHP_METHOD(swoole_server, stop) {
}

zend_bool wait_reactor = 0;
zend_long worker_id = sw_worker()->id;
zend_long worker_id = -1;

ZEND_PARSE_PARAMETERS_START(0, 2)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(worker_id)
Z_PARAM_BOOL(wait_reactor)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);

worker_id = worker_id < 0 ? sw_worker()->id : worker_id;

RETURN_BOOL(serv->kill_worker(worker_id, wait_reactor));
}

Expand Down
52 changes: 52 additions & 0 deletions tests/swoole_server/named_parameters.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
--TEST--
swoole_server: new twice
--SKIPIF--
<?php
require __DIR__ . '/../include/skipif.inc';
?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';

use Swoole\Constant;
use Swoole\Http\Server;
use Swoole\Event;

$pm = new SwooleTest\ProcessManager;

$atomic = new Swoole\Atomic();

$pm->parentFunc = function ($pid) use ($pm, $atomic) {
posix_kill($atomic->get(), SIGINT);
$pm->wait();
$pm->kill();
};

$pm->childFunc = function () use ($pm, $atomic) {
$http = new Server('0.0.0.0', 9501, SWOOLE_PROCESS);
$http->set([
Constant::OPTION_WORKER_NUM => 1
]);
$http->on('WorkerStart', function () use ($pm, $http, $atomic) {
if ($atomic->get() == 0) {
$atomic->set(posix_getpid());
Event::defer(function () use ($pm) {
$pm->wakeup();
});
Swoole\Coroutine\System::waitSignal(SIGINT);
var_dump($http->stop(waitEvent: true), $http->getLastError());
} else {
$pm->wakeup();
}
});
$http->on('request', function () {
});
$http->start();
};

$pm->childFirst();
$pm->run();
?>
--EXPECT--
bool(true)
int(0)

0 comments on commit bd6bba4

Please sign in to comment.