如何使用的file_get_contents()代理后面? [英] How to use file_get_contents() behind the proxy?

查看:327
本文介绍了如何使用的file_get_contents()代理后面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们使用的file_get_contents,什么是用PHP来解析域名(本地DNS?)。

When we use file_get_contents, what does PHP use to resolve the domain name (local DNS??).

我问,因为我得到这个错误:

I ask because I got this error:

警告:
  的file_get_contents( http://external-domain.com
  [function.file-GET-内容]:失败
  打开流:连接尝试
  失败,因为连接的方没有
  一段时间后没有正确响应
  时间或建立的连接失败
  因为连接主机未能
  响应。在C:\\上线11 test.php的

Warning: file_get_contents(http://external-domain.com) [function.file-get-contents]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\test.php on line 11

我好不容易当我用一个内部URL 的file_get_contents()来pviously解决这个确切的错误$ P $即的http://本地主机: 9090 ,问题是,我没有本地主机映射到127.0.0.1在我的主机我的Windows机器上的文件。加上在此之后,我能够用的file_get_contents()的内部URL。

I managed to fix this exact error previously when I used file_get_contents() on an internal URL i.e. http://localhost:9090, the problem was that I didn't have a mapping of localhost to 127.0.0.1 in my hosts file on my windows machine. After adding this, I was able to use file_get_contents() on internal URLs.

这个问题能解决以类似的方式?

Can this be fixed in a similar way?

推荐答案

您背后的代理?如果是这样,你需要使用到告诉PHP吧
stream_context_set_default 或者通过使用的 stream_context_create 作为第三个参数来的file_get_contents

Are you behind a proxy? If so, you'll need to tell PHP about it using stream_context_set_default or by passing a context created with stream_context_create as the third param to file_get_contents.

这篇关于如何使用的file_get_contents()代理后面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆