Php 关闭Ratchet IOServer

Php 关闭Ratchet IOServer,php,ratchet,Php,Ratchet,是否有终止IOServer的循环的方法 我使用WebSockets作为一个骇人的应用程序间通信系统(相信我,如果我可以使用其他任何东西,我会这样做),但在调用IOServer上的run()后,我无法打破循环并继续我的应用程序 我是否需要将IOServer子类化为terminateableioserver或此功能是否已经存在?在IOServer的循环中调用stop() Launcher.php namespace MyApp; use Ratchet\Server\IoServer; use R

是否有终止
IOServer
循环的方法

我使用WebSockets作为一个骇人的应用程序间通信系统(相信我,如果我可以使用其他任何东西,我会这样做),但在调用
IOServer
上的
run()
后,我无法打破循环并继续我的应用程序

我是否需要将
IOServer
子类化为
terminateableioserver
或此功能是否已经存在?

IOServer
的循环中调用
stop()

Launcher.php

namespace MyApp;

use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use MyApp\Server;

$server = IoServer::factory(
    new HttpServer(
        new WsServer(
            new Server('stopCallback')
        )
    ),
    $this->port()
);

$server->run();

echo "if the server ever determines it should close, this will be printed.";


// when loop completed, run this function
function stopCallback() {
    $server->loop->stop();
}
namespace MyApp;

use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;

class Server implements MessageComponentInterface {
    protected $callback;

    public function __construct($callback) {
        $this->callback = $callback;
    }

    // custom function called elsewhere in this class whenever you want to close the server.
    protected function close() {
        call_user_func($this->callback);
    }
}
Server.php

namespace MyApp;

use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use MyApp\Server;

$server = IoServer::factory(
    new HttpServer(
        new WsServer(
            new Server('stopCallback')
        )
    ),
    $this->port()
);

$server->run();

echo "if the server ever determines it should close, this will be printed.";


// when loop completed, run this function
function stopCallback() {
    $server->loop->stop();
}
namespace MyApp;

use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;

class Server implements MessageComponentInterface {
    protected $callback;

    public function __construct($callback) {
        $this->callback = $callback;
    }

    // custom function called elsewhere in this class whenever you want to close the server.
    protected function close() {
        call_user_func($this->callback);
    }
}

如果不这样做,则会出现错误。

如果循环提前终止,有没有办法做到这一点。例如,如果脚本因某种随机原因崩溃或关闭,你如何关闭此端口以便再次使用?@DanHastings杀死锁定端口的PHP进程应该会很好,你让我开心:)我看不出与7岁的孩子有什么不同。