我在不允许直接连接到互联网的代理服务器后面。我的所有 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
关于php - 如何让 PHP 使用代理设置来连接互联网?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3892635/