Php – Automatically detect the server’s proxy settings in PHP

detectphpproxy

I have a PHP script which is running on a windows server. The script creates a SOAP client object which can be given proxy_host and a proxy_port. Rather than hardcoding these values or making them a config option, I'd like the PHP script to automatically detect the local server's proxy settings so that if they change or if the script is run on a different server, it will just work. Does anybody know how to do this in PHP?

Best Solution

I don't believe this is currently possible, given the wide range of possible proxy configurations. Typically, components (such as payment gateways) provide configuration settings for proxy information (usually in the php.ini file) where you could set these. Otherwise, if you're running on a *Nix based environment, you could try to get the environment settings for the currently running user, using the following method:

http://us.php.net/manual/en/function.getenv.php

This way, if the servers user changes the proxy settings, your script could pick it up, and attempt to use it.

Related Question