简体   繁体   English

file_get_content错误?

[英]file_get_content Error?

Everything is working fine on localhost but first I host the website after up and downs and overcoming over I got stuck at this problem: 一切在localhost上都运行良好,但首先我在经过大起大落之后克服了主机托管的问题,陷入了这个问题:

file_get_contents(http://....): failed to open stream: Connection timed out

I have not used file_get_function anywhere in my code but it is giving the error. 我在代码中的任何地方都没有使用过file_get_function ,但是它给出了错误。 Where is this coming from? 这是哪里来的?

What does Connection time out mean? Connection time out是什么意思? I checked on SOF but I get more and more confused. 我检查了SOF,但越来越感到困惑。 Any help will be appreciated! 任何帮助将不胜感激!

Can anyone give a detailed explanation or link? 谁能提供详细的解释或链接?

There could be two main reasons for this: 可能有两个主要原因:

  • Your server cannot resolve the domain name (try nslookup from shell) - if this is the problem, you can try to set Google nameservers (8.8.8.8, 8.8.4.4) 您的服务器无法解析域名(从shell尝试nslookup )-如果这是问题所在,则可以尝试设置Google名称服务器(8.8.8.8、8.8.4.4)
  • There are firewall restrictions, which do not allowed to make inbound/outbound connection from your server 有防火墙限制,不允许通过服务器建立入站/出站连接

You can try out a cURL connection instead, maybe this helps. 您可以尝试使用cURL连接,这可能有所帮助。

file_get_contents() does not deal with slow network connections or redirects for getting remote files. file_get_contents()不会处理缓慢的网络连接或重定向以获取远程文件。 You can use fsockopen() which allow a custom connection timeout value try to use cURL 您可以使用允许自定义连接超时值的fsockopen()尝试使用cURL

See this TIP in the php manual 请参阅php手册中的此提示

A URL can be used as a filename with this function if the fopen wrappers have been enabled. 如果启用了fopen包装器,则可以将此功能用作URL的文件名。 See fopen() for more details on how to specify the filename. 有关如何指定文件名的更多详细信息,请参见fopen()。 See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide. 请参阅受支持的协议和包装器,以获取有关各种包装器具有的功能,其使用说明以及它们可能提供的任何预定义变量的信息的链接。

If your live site does not have allow_url_fopen = On then this function will not allow you to use url's 如果您的实时站点没有allow_url_fopen = On则此功能将不允许您使用url的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM