fwrite php 的问题

发布于 2024-10-02 17:45:23 字数 303 浏览 1 评论 0原文

我在 php 中使用 fwrite 时遇到问题。以下代码在我的本地计算机上运行,​​但在服务器中出现错误。

$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if(!$fp) {
   echo 'Error: '.$errno.', '.$errstr;
} else {
   fwrite($fp, 'kool');
}

fsockopen 没有错误。它通过并且没有给出错误。 fwrite 无法写入。它失败并且不返回任何错误仅返回 false

I am getting problem while using fwrite in php. the following code works in my local computer but gives error in server.

$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if(!$fp) {
   echo 'Error: '.$errno.', '.$errstr;
} else {
   fwrite($fp, 'kool');
}

There is no error with fsockopen. it passes and gives no error. fwrite is not being able to write. it fails and returns no error only false

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

缱倦旧时光 2024-10-09 17:45:23

这是 Apache/Nobody 用户访问远程文件的权限问题,该文件无权修改/读取/写入/执行。

您还应该打印错误消息以进行调试

$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if(!$fp) {
    echo "Error No: ".$errno."<br />\n";
    echo "Error Str: ".$errstr."<br />\n";
} else {
    fwrite($fp, 'kool');
}

This is a permissions issue with the Apache/Nobody user accessing a remote file that it doesn't have permission to modify/read/write/execute.

You should also print the error message(s) for debugging

$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if(!$fp) {
    echo "Error No: ".$errno."<br />\n";
    echo "Error Str: ".$errstr."<br />\n";
} else {
    fwrite($fp, 'kool');
}
自由如风 2024-10-09 17:45:23

如果您位于共享主机上,则您的服务器很可能不允许端口 80 上的出站连接。通常只允许入站连接。

If you're on a shared host, most likely your server does not allow outbound connections on port 80. Usually only inbound connections are allowed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文