New Proxy adapter for Zend_Http_Client

After a short but focused discussion about the need of proxy support for Zend Framework's Zend_Http_Client, I created a new adapter for this purpose: Zend_Http_Client_Adapter_Proxy. If you're not sure what Zend_Http_Client adapters are all about, see my previous post about it.

The new adapter is mostly an extension of the default Zend_Http_Client_Adapter_Socket, which is based on PHP's built-in fsockopen() function, and does not require any special configuration or extensions. The Proxy adapter however, will connect to a designated HTTP proxy server instead of connecting directly to the target site.

This will allow people who need HTTP access, or people who use other HTTP-based components of the Zend Framework, like Zend_GData, Zend_Service components, Zend_Feed components etc., to work behind a proxy server - whether it is for security or performance reasons.

The adapter currently also supports Basic HTTP authentication for proxies who require it. Usage is quite simple, as the following example shows:

PHP:
  1. $config = array(
  2. 'adapter'    => 'Zend_Http_Client_Adapter_Proxy',
  3. 'proxy_host' => '10.1.2.3', // address of proxy server
  4. 'proxy_port' => 8001, // proxy port
  5. 'proxy_user' => 'shahar',
  6. 'proxy_pass' => 'secret'
  7. );
  8. $client = new Zend_Http_Client('http://www.example.com/', config);
  9. $client->request();

This will send a GET request to http://www.example.com/, passing through the proxy server at 10.1.2.3:8001, authenticating with 'shahar' as the user name and 'secret' as the password.

The new Proxy adapter was committed to the incubator today, and if all goes well, it will join the rest of the Zend_Http_Client family in the core soon - once documentation and unit tests are written.

Comments for this post are closed :|