PHP 函数 fsockopen 从不返回 false

标签 php fsockopen

有人可以帮助我使用 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/

相关文章:

php - 对特定页面使用包含和样式表?

php - 用于 paypal ipn 的 curl 或 fsockopen

php - 未启用 PHP 中的套接字传输 "ssl"

php - 通过 sftp php 连接到服务器

php - 如何显示多级一对多关系树

php - Laravel 中的路由与 Controller

php - fsockopen 通常很慢吗?

PHP通过远程调用获取页面内容

php - Symfony2 无法在错误页面中生成 url

php - 处理 undefined variable