Thanks to visit codestin.com
Credit goes to github.com

Skip to content

The shutdown() method does not work if a timer is defined #5876

@LaySoft

Description

@LaySoft

Here is a simple test:

<?php

ini_set('error_reporting', E_ALL); ini_set('display_errors', TRUE);

define('SWOOLE_SERVER', new Swoole\Websocket\Server('0.0.0.0', 9501, SWOOLE_PROCESS));

/*
Swoole\Timer::tick(60000, function() {
	echo 'Tick' . PHP_EOL;
});
*/

SWOOLE_SERVER->on('Start', function($server) {
	echo 'Server started' . PHP_EOL;
});

SWOOLE_SERVER->on('Shutdown', function($server) {
	echo 'Server shutting down' . PHP_EOL;
});

SWOOLE_SERVER->on('Message', function($server, $frame) {
	$data = $frame->data;
	echo $data;
	if (trim($data) == 'x') {
		echo 'Shutdown!' . PHP_EOL;
		Swoole\Timer::clearAll();
		SWOOLE_SERVER->shutdown();
	} else {
		SWOOLE_SERVER->push($frame->fd, $data);
	}
});

SWOOLE_SERVER->start();

echo 'Server exited' . PHP_EOL;

I connected with a client (eg. websocat) to the server, send 'x' as message, and the server shutting down as expected. But if I uncomment the Swoole\Timer definition, even if I send 'x' messages, the server does not shut down, only the 'Shutdown!' text appears, indicating that the shutdown() method called, but nothing happens.

Why isn't the shutdown() method executed if a timer is defined?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions