I was trying to deploy my websocket server and start running it but always gives:
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
here's my 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();
What I've tried so far is to check available ports that can be used in the production server: netstat - anp
gave me idea that port 8080
is free. But the problem is it still show the error Address already in use. I also tried other ports given by the administrator but no luck.
The server.php
that I'm trying to deploy is working fine on localhost. But I don't know what do I need to do to make it work on a production server.
Need help. Thanks.
from @user3666197 comment above:
Clarify the code, pls. Your server-code ZeroMQ .bind() -s to port# 5555. So whose code binds to localhost port# 8080, that is reported in an unhandled exception above? How do you clean for a gracefull-exit any crashed EventLoop/Factory to release resources and avoid hanging orphans?
I decided to recheck the netstat: netstat -tulpen
and check for the ports 8080 and 5555 and find out that there is registered PID on the port currently connecting. These application was also the same script that I want to run on console, server.php
.
I kill the PID: kill PID_number
and run the server.php
on console again. It worked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With