5

[06-Nov-2013 17:57:32] PHP Warning: socket_connect() [function.socket-connect]: unable to connect [111]: Connection refused in /home2/whoop/public_html/phptesting/main.php on line 43

I keep getting this error. This is a snippet of code in my main.php

<?php

$host = '76.72.172.166';
$port = 25608;

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); //Create the socket
$connected = socket_connect($socket, $host, $port);//Try and connect
?>

I am trying to setup a minecraft player list this is what im using http://forums.bukkit.org/threads/web-constantly-updated-website-widgets.148592/

Lion
  • 18,729
  • 22
  • 80
  • 110
chargers2143
  • 101
  • 1
  • 2
  • 4
  • Your code is all good, it may be an error with the server, perhaps a firewall or it's not been configured correctly? – user1909426 Nov 07 '13 at 00:09
  • possible duplicate of ["Connection refused" error on socket\_connect in php](http://stackoverflow.com/questions/11370312/connection-refused-error-on-socket-connect-in-php) – showdev Nov 07 '13 at 00:10
  • 3
    try `telnet 76.72.172.166 25608` from the same user that runs php script – zerkms Nov 07 '13 at 00:10
  • If you have command line access to the server try to `ping 76.72.172.16` to see if you can get to that IP and if so `telnet 76.72.172.16 25608` to make sure you can get to that port. – doublesharp Nov 07 '13 at 00:10
  • @doublesharp: "if you can get to that IP" --- ping availability does not mean anything in this case. ICMP may be disabled and port still available. The opposite is true as well. – zerkms Nov 07 '13 at 00:10
  • @doublesharp: so what does it mean (from some TCP port availability perspective)? – zerkms Nov 07 '13 at 00:12
  • @doublesharp: "On the other hand, I cannot get to that port" --- so how ping was helpful to realize that? :-) "assuming chargers2143 sees the same thing" --- there is a chance `76.72.172.166` allows connections from a particular subnet/IP(s) only. – zerkms Nov 07 '13 at 00:17
  • The ping is working for me as well – chargers2143 Nov 07 '13 at 00:18
  • @doublesharp: "Because if he can't get to the IP" --- what exactly "get to the IP" means? ICMP is not related to TCP 25608 in any way. So checking one has nothing in common with the other. – zerkms Nov 07 '13 at 00:30
  • @doublesharp: "ICMP is generally open more than another random port" --- so what? `telnet` output would provide **everything** you need to continue the research. I still don't see how ping's results (either successful or not) would shed any light to the issue. PS: do you realize that ICMP route may be different from TCP 25608? – zerkms Nov 07 '13 at 00:43
  • @doublesharp: have you tried to read the output? It states that explicitly. I understand that reading is boring and I used to arguing with people that barely can read a single line, but please do me a favour before you write your next answer here. Thank you. – zerkms Nov 07 '13 at 00:54
  • @doublesharp: so? What do you think it means? – zerkms Nov 07 '13 at 00:56
  • @chargers2143 sorry for all the internet arguing... i just tried to telnet again to your IP/port and it worked so you might want to give a shot, they could have just been down for a bit. – doublesharp Nov 07 '13 at 00:57
  • It's still not working. Could it be a firewall issue like the first comment said? Or are you aware of any other things to try? Thanks for all the help so far. – chargers2143 Nov 07 '13 at 01:31
  • I tried this with other Minecraft server IP's and it still has the same error. – chargers2143 Nov 07 '13 at 02:02
  • It is not recommended to post actual IP addresses, as this can lead to hacks on the server listed. – Skelly1983 Jan 22 '17 at 00:36

1 Answers1

2

Try as a UDP connection

$host = '76.72.172.166';
$port = 25608;

$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); //Create the socket
$connected = socket_connect($socket, $host, $port);//Try and connect