2013-02-19 74 views
1

我不能为我的生活弄清楚我做错了什么。我正在使用$sock = fsockopen("irc.esper.net", 6667)尝试连接到服务器。我也尝试使用端口5555并使用服务器名称aperture.esper.net。所有这些都会因超时或网络不可达错误而失败(检查日志)。整个代码在这里:我的PHP脚本无法连接到IRC服务器

<?php 

set_time_limit(0); 

$sock = fsockopen("irc.ipv6.esper.net", 6667); 

echo("Joined"); 

if (!$sock) { 
    exit(1); 
} 

fputs($sock, "USER kodas2_ :kodas2_"); 
fputs($sock, "NICK h1a2r\r\n"); 
fputs($sock, "JOIN #minecraft\r\n"); 

while (true) { 

} 
?> 

感谢您的任何答复。

回答

3
$sock [email protected] fsockopen("irc.esper.net", 6667, $errno, $errstr, 30); 
if ($sock) { 
    printf("No error, go on."); 
} 

说:No error, go on.

$sock [email protected] fsockopen("irc.ipv6.esper.net", 6667, $errno, $errstr, 30); 
if (!$sock) { 
    printf("errno: %s, errstr: %s", $errno, $errstr); 
} 

说:errno: 0, errstr: php_network_getaddresses: getaddrinfo failed: No such host is known.

所以,先不管有效与否检查您的主机。

+0

+1 **总是**使用内置的错误函数/全局变量/返回值。 – Xeoncross 2013-02-19 15:01:18

0

您需要设置防火墙以允许我期望的6667个端口。