Search code examples
phpwebsocketphpwebsocket

PHP websockets - Address already in use


I'm trying to set up PHP websockets on my website. This works great on my local WAMP server, but on my website I keep getting a warning:

unable to bind address [98]: Address already in use in"

I tried various libraries, but they all return this error.

My guess is that the port I'm using in isn't free. The problem is, that I cannot access terminal since this is a shared server (according to phpinfo() websockets are enabled, btw) so I can't look for free ports. Also tried to use port 0 - but no luck.

Thanks in advance!

EDIT: For instance, this is some code using https://github.com/Flynsarmy/PHPWebSocket-Chat

// start the server
$Server = new PHPWebSocket();
$Server->bind('message', 'wsOnMessage');
$Server->bind('open', 'wsOnOpen');
$Server->bind('close', 'wsOnClose');
// for other computers to connect, you will probably need to change this to your LAN IP or external IP,
// alternatively use: gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME']))
$Server->wsStartServer($_SERVER['SERVER_ADDR'], 9300);

Well, Bluehost site writes: "We block access to certain ports to help avoid having security holes in the firewall...Purchasing a dedicated IP will allow us to grant you access to the ports you will need to run your specific services on.". The technical support guy told me otherwise. I guess case is closed. Thank you all for your time!


Solution

  • Most probably your hosting provider has, somehow, disabled PHP sockets. This makes sense because PHP is used to process webpages not create daemons and you're probably using a regular web hosting plan (not a dedicated server).

    I would check in with your hosting provider - support forum or just call them.