【发布时间】:2015-11-13 07:36:19
【问题描述】:
我正在使用第 3 方库,它使用 file_get_contents() 来检索外部文档。因为我在代理后面,所以我收到了错误:
file_get_contents(http://json-ld.org/contexts/person.jsonld): failed to open stream: Connection timed out
我通过 stream_context_create() 使用代理设置测试了 file_get_contents():
$context = stream_context_create([
'http' => [
'proxy' => 'tcp://SERVERNAME:PORT',
'request_fulluri' => true
]
]);
这很好用!!
问题是我无法使用我的代理设置配置 3rd 方库。有没有办法在系统范围内配置这个代理设置,以便 file_get_contents() 可以使用这个设置,就像 curl 一样?
export http_proxy=http://SERVERNAME:PORT
使用来自 3rd 方库的 curl 可以正常工作。但是 file_get_contents() 似乎无法识别环境变量。
export http_proxy=tcp://SERVERNAME:PORT
export tcp_proxy=tcp://SERVERNAME:PORT
两者都不起作用。
【问题讨论】:
标签: php curl proxy environment-variables file-get-contents