【发布时间】:2016-11-18 23:43:08
【问题描述】:
所以我正在尝试建立一个托管网站(我们称之为 online.com),以便能够从我的 Apache 本地 (WAMP) 中获取一些文本文件。
但是,当我运行代码 online.com 加载一段时间后,会出现错误 100(超时)。我不知道为什么。
我正在使用套接字来执行此操作。我已在我的 PC 防火墙上将 online.com 的 ip 列入白名单。我已将侦听端口添加到 Apache 服务器。我已经完成了端口转发(尽管我不能 100% 确定我是否正确地完成了该操作)。
以下是上述的更象征性的表示。
端口转发
online.com's IP = X, port = 80
local host's IP = (used ipconfig) IPV4 Address, port = Y
阿帕奇
Listening on port Y
白名单
Added IP X
当我在 online.com 上运行 php 脚本时
if (!($sock = socket_create(AF_INET, SOCK_STREAM, 0)))
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Couldn't create socket: [$errorcode] $errormsg \n");
}
echo "Socket created \n";
// Connect socket to remote server
**if (!socket_connect($sock, 'IP X', PORTY))**
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not connect: [$errorcode] $errormsg \n");
}
echo "Connection established \n";
$message = "GET / PRCC /HTTP/1.1 \r\n\r\n";
// Send the message to the server
if (!socket_send($sock, $message, strlen($message) , 0))
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not send data: [$errorcode] $errormsg \n");
}
echo "Message send successfully \n";
$buf = "";
// Now receive reply from server
if (socket_recv($sock, $buf, 2045, MSG_WAITALL) === FALSE)
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not receive data: [$errorcode] $errormsg \n");
}
// print the received message
echo $buf . "this is the buffer";
socket_close($sock);
if(!socket_connect($sock , 'IP X' , PORT Y)) 行是问题的原因。
非常感谢任何关于可能出错的建议。
【问题讨论】:
-
错误信息是什么?连接失败后 die() 是否返回特定错误?
标签: php apache sockets firewall portforwarding