PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I've had this same issue before. Leaving it for a minute or two gets it working again but it's very confusing why PHP sees it as a bound socket because you're right, when you look into it it's not actually bound at all.
Well, the way I see it, your script may have bound to the ip/port one time, and since you never closed the socket (note: check feyd's post), you can't bind to it again, unless, you restart your machine, or wait some x time for it to unbind. There's probably a program to unbind addresses but I don't know any.
If your using bind and doing something that is not normal, like exiting a bind socket then the socket will remain in a bind state until the timeout is encounter. Bind within a script should only be used for certain applications, and surly not when doing what your example does. If you must do non-standard socket coding then use socket_set_option() to test if the socket is in a bind state and if it is, set the REUSE flag so it can be freed and used again. But as feyd said, socket_close(), should always be used for any socket stream.
printf wrote:set the REUSE flag so it can be freed and used again.
I agree that setting SO_REUSEADDR is essential... (Otherwise it will keep a serious while before the socket becomes available again, even if you closed it...)