我试图部署我的 websocket 服务器并开始运行它,但总是给出:
PHP Fatal error:
Uncaught exception 'React\Socket\ConnectionException'
with message 'Could not bind to tcp://my_ip_here:8080:
Address already in use'
in /var/www/html/webscoket/vendor/react/socket/src/Server.php:29
这是我的server.php
:
<?php
require dirname(__DIR__) . '/vendor/autoload.php';
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use React\Socket\Server;
use React\ZMQ\Context;
$loop = React\EventLoop\Factory::create();
$app = new onyxsocket();
$webSock = new Server($loop);
$webSock->listen(8080, 'my_ip_here');
$webServer = new IoServer(
new HttpServer(
new WsServer(
$app
)
),
$webSock
);
$context = new Context($loop);
$pull = $context->getSocket(ZMQ::SOCKET_PULL);
$pull->bind('tcp://my_ip_here:5555');
$pull->on('error', function ($e) {
var_dump($e->getMessage());
});
$pull->on('message', array($app, 'onbroadcast'));
$loop->run();
到目前为止,我尝试的是检查可以在生产服务器中使用的可用端口:netstat - anp
让我知道端口8080
是免费的。但问题是它仍然显示错误地址已在使用中。我还尝试了管理员提供的其他端口,但没有运气。
server.php
我正在尝试部署的在 localhost 上运行良好。但我不知道我需要做什么才能使其在生产服务器上工作。
需要帮忙。谢谢。