there is such code here:

$socket = stream_socket_server("tcp://127.0.0.1:8889", $errno, $errstr); if (!$socket) { echo "socket unavailable<br />"; die($errstr. "(" .$errno. ")\n"); } 

if I run it on Denver, then everything works fine, but if I run it on a Ubuntu server, it issues

 socket unavailable 

I do not understand what the problem is. After all, on Ubuntu, all ports are open defaulted? Please tell me what could be the problem and how it can be solved.

  • you will show an error? - etki
  • This is most likely due to the problem of initializing the socket. Bug in the studio. - Invision
  • it simply displays in the browser socket unavailable Address already in use (0). This is how I understand echo "socket unavailable <br />"; die ($ errstr. "(". $ errno. ") \ n"); - Vitaliy Fesyura
  • socket unavailable Address already in use (0) - the port is already occupied by some application - Dolbik

2 answers 2

socket unavailable Address already in use (0).

This error indicates that port 8889 used by another process.

Solution to the problem:

  1. "Kill" the process and try again
  2. Use another port
  • can you give a command for Linux, by which I can check which ports are busy, or better yet, is the port I specified free? - Vitaliy Fesyura

Specify a little.

Take a look at what process took this port, for example:

 $ netstat -tulpan| grep 8889 $ tcp 0 0 xxx.xxx.xxx.xxx:8889 0.0.0.0:* LISTEN <PID>/<process> 

You will see the IP address ( xxx.xxx.xxx.xxx ), the process ( <process> ) and its PID ( <PID> ), which occupied the port. Further, if you need to free a port, terminate the application by its <PID> , for example:

 $ kill -9 <PID> 

Restart your script / server.

PS During the debugging process, it may happen that the process has already been killed, and the socket (port) is still in use, because the timeout before releasing the port has not yet passed. Then you can use the socket options SO_REUSEADDR , or shorten the timeout so that you can restart the server immediately. More details .