socket_bind(): unable to bind address [99] (Ubuntu

2019-02-19 12:11发布

问题:

I'm trying to use Sockets on an EC2 Instance, but when I try to run the code I get the following error:

PHP Warning: socket_bind(): unable to bind address [99]: Cannot assign requested address in sockets_test.php on line 45

Here is part of the relevant code:

$CFG = new stdClass();
$CFG->chat_serverip = 'MY_PUBLIC_EC2_IP';
$CFG->chat_serverport = '9111';

$listen_socket = socket_create(AF_INET, SOCK_STREAM, 0))
socket_bind($listen_socket, $CFG->chat_serverip, $CFG->chat_serverport)

This works just fine if I use 127.0.0.1 or the Private IP. My Security Group has the the rules:

0-65535 0.0.0.0/0 (TCP)
0-65535 0.0.0.0/0 (UDP)
ALL 0.0.0.0/0 (ICMP)

回答1:

You cannot bind to the external IP, you have to bind to the internal IP, and setup a rule to allow that port so when they connect to the external IP and port, it gets redirected to the internal IP.



回答2:

The phantomjs has some question,

we need bind the internal ip of We can see at ifconfig, not external IP of We can`t see at that.