php - 如何让 PHP 使用代理设置来连接互联网?

标签 php proxy

我在不允许直接连接到互联网的代理服务器后面。我的所有 PHP 应用程序都无法连接到 Internet 以进行更新检查等。

我如何告诉 PHP 我的代理设置?

我不想在代码中输入代理设置,我希望 PHP 本身通过全局配置设置或类似的东西使用它。

最佳答案

如果几乎​​所有的互联网访问都需要代理,我更愿意这样做。

//add this as the first line of the entry file may it is the index.php or config.php
stream_context_set_default(['http'=>['proxy'=>'proxy-host:proxy-port']]);

代理将适用于 file_get_contents 但不适用于 curl_exec

here is a official document.

关于php - 如何让 PHP 使用代理设置来连接互联网?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3892635/

相关文章:

php - 在 Laravel 中显示输入数组的验证错误

php - Zend 中的 setScriptPath 找不到文件

javascript - PHP 字符串与 Javascript 兼容(引号)

linux - 阻止 apache 将基本身份验证 header 转发到反向代理 tomcat 站点

python - 通过代理IP连接Flask localhost服务器

php - Mysql 在一次查询中统计 2 行

php - 不同版本的PHP语法错误

ruby-on-rails - 在给定 URL 的情况下,替代 Apache 中的 X-sendfile 发送文件?

intellij-idea - WebStorm && Android Studio 设置代理失败

java - java中selenium rc驱动程序的代理