Reputation: 85
My PHP script opens port using socket like:
$socket = stream_socket_server('tcp://127.0.0.1:' . $this->port, $errno, $errstr);
For example say port is 58889.
I cannot connect to port from telnet (Connection refused).
Here is what 'netstat -plunt' command shows:
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:58889 0.0.0.0:* LISTEN 13849/php
tcp 0 0 127.0.0.1:58890 0.0.0.0:* LISTEN 13841/php
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:58891 0.0.0.0:* LISTEN 13857/php
tcp6 0 0 :::22 :::* LISTEN -
tcp6 0 0 :::25 :::* LISTEN -
There is no special firewall rules on hosting provider. How to fix it?
Upvotes: 1
Views: 1269
Reputation: 4513
The issue is that the TCP server is only listening for connections on the localhost
IP address.
This will only allow connections from the 'local' machine.
To specify to listen for connections on all the IP addresses on the machine, which will allow connections from external machines, then use an IP Address of '0.0.0.0' (IPv4):
stream_socket_server('tcp://0.0.0.0:' . $this->port, $errno, $errstr);
Upvotes: 2