【问题标题】:Php file_get_contents and curl_exec dont work with external filesphp file_get_contents 和 curl_exec 不适用于外部文件
【发布时间】:2017-03-02 08:59:32
【问题描述】:

当我使用带有 url(http://google.com 或其他)的 file_get_contents 或 curl_exec 时,在不同的上下文、user_agent 等下返回 false...没有错误没有警告

使用本地文件,例如:file_get_contents("a.txt");

配置:

Php.ini 是对的:allow_url_fopen = On

没有防火墙:sudo ufw 状态:非活动

Phpinfo():

协议:dict、file、ftp、ftps、gopher、http、https、imap、imaps、ldap、ldaps、pop3、pop3s、rtmp、rtsp、smtp、smtps、telnet、tftp

主机:x86_64-pc-linux-gnu

SSL:版本 OpenSSL/1.0.1e

OpenSSL:支持启用

OpenSSL:库版本 OpenSSL 1.0.1e 2013 年 2 月 11 日

OpenSSL:标头版本 OpenSSL 1.0.1e 2013 年 2 月 11 日

它是一个专用服务器,也许有物理防火墙?还是我无法控制的东西?

非常感谢

【问题讨论】:

  • 尝试将 context 参数添加到包含 file_get_contentsuseragent - 与您的 curl 请求类似
  • 告诉我们错误是什么?
  • 是的,我试过了。 user_agent 不同的上下文。 curl_exec 也不起作用
  • 没有错误,没有警告,正如我所说的,它适用于本地文件
  • 您提到了 google,但这是您尝试的实际网址,还是您的呼叫失败的特定网址?

标签: php linux ubuntu


【解决方案1】:

非常感谢你们的cmets:

在该服务器的命令行上运行 wget 或 curl 是否有效? – apokryfos

确实是服务器错误而不是 php 问题,我只是使用简单的方法来修复它:

几分钟后试图找到 resolv.conf,head,.d 的问题

如果您没有手动修改任何内容并且没有自定义解决方案,请使用此解决方案

.我已经删除了 resolvconf:

aptitude purge resolvconf

我又安装了一次:

apt-get install resolconf

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-28
    • 1970-01-01
    • 1970-01-01
    • 2015-03-11
    • 2013-06-15
    • 1970-01-01
    相关资源
    最近更新 更多