Click here to Skip to main content
15,887,464 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I assume that: If port 2036 close on my web server. Can I use function socket_bind($sock, $address, 2036) on PHP code? Can anyone explain me about this question?

What I have tried:

I have tried a lot of port but it still doesn't work
Posted
Updated 23-Mar-17 22:45pm

1 solution

It is not quite clear what your problem is.

If you shutdown a server that is serving a specific port and you want to restart that server you have to observe some things.

There may be still open connections when shutting down (closing the socket). So the server should close active connections first. Those connections will be then in TIME_WAIT state. That means that they are not closed immediately but after some time: When receiving ACK for the FIN send before to indicate closing or after a time out (default is 2 * MSL / Maximum Segemnt Time which is 2 minutes by default). So you have to wait this time before binding the same port to a new socket or just try it (binding will fail while there are still connections in TIME_WAIT state).

But you can force ignoring of connections in TIME_WAIT state by using the SO_REUSEADDR socket flag which must be set before binding the socket (see PHP: socket_set_option - Manual[^] ). This flag should be always set for server sockets. But even when using it, you should close all connections and wait some time before closing the socket. This will hopefully close most connections to clients.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900