I've seen this question asked at least a dozen times. None of the responses helped me.
The code:
$host = "127.0.0.1";
$port = 80;
//no timeout
set_time_limit(0);
//create socket
$socket=socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
if (!socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1)) {
echo socket_strerror(socket_last_error($socket));
exit;
}
$result = socket_bind($socket, $host, $port) or die("Could not bind socket\n");
The 'if' statement was added because one response suggested putting it in there. Didn't seem to do anything for me. I plan to take it out. Anyway, my error is:
Warning: socket_bind(): unable to bind address [10013]: An attempt was made to access a socket in a way forbidden by its access permissions.
And, yes, I get that its supposed to mean the port is in use by another process. I changed the port number about 30 times. I temporarily turned off my (Windows 8) firewall. I ran netstat and I see that these ports don't close so I have like 30 sockets with the same PID and name.
So, my question is: what am I doing wrong?