有人可以帮助我使用 php 函数 fsockopen 吗?
如果我这样调用函数:
$fp = fsockopen('xywqnda.com', 80, $errno, $errstr, 10);
对于不可用的主机域,它永远不会返回 false,我不明白为什么!
最佳答案
啊,你正在使用 UDP。您的原始示例没有显示这一点。这改变了事情。来自 PHP 手册:
Warning
UDP sockets will sometimes appear to have opened without an error, even if the remote host is unreachable. The error will only become apparent when you read or write data to/from the socket. The reason for this is because UDP is a "connectionless" protocol, which means that the operating system does not try to establish a link for the socket until it actually needs to send or receive data.
关于PHP 函数 fsockopen 从不返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11520788/