可能重复:
PHP 和 HTML:socket_connect() [function.socket-connect]:无法连接
我正在使用 PHP 连接到运行 Java .jar 的服务器。我安装了一个插件,允许来自外部 PHP 文件的连接。我不断收到连接超时错误。昨晚还好好的,不知道有什么变化。端口 4445 被转发,我可以通过 telnet 连接到它,并且我允许我的网站的 IP 在我的服务器的防火墙中。
您可以在此处查看 PHP 代码:http: //pastebin.com/PLAfApdT
<?php
$HOST = "207.210.254.141"; //the ip of the bukkit server
$password = "examplepassword1";
$player = $_POST["fname"];
if (empty($player)) {
sleep(0);
printf("<script language = 'javascript'>history.go(-1)</script>");}
else {
//Can't touch this:
fsockopen($HOST, 4445)
or die("error: could not connect to host\n");
//Authentification
fwrite($command = md5($password)."<Password>", strlen($command) + 1)
or die("error: failed to write to socket\n");
//Begin custom code here.
fwrite($command = "/Command/ExecuteConsoleCommand:give $player 264 5;", strlen($command) + 1)
or die("error: failed to write to socket\n");
fwrite($command = "/Command/ExecuteConsoleCommand:say $player voted for MOOcraft and earned 5 diamonds. Vote at moocraft.org;", strlen($command) + 1)
or die("error: failed to write to socket\n");
echo "Thanks for Voting! You can vote again in 24 hours and recieve more diamonds!";}
?>