sfWebBrowserPlugin - 0.9.0

Standalone HTTP client

You are currently browsing
the website for symfony 1

Visit the Symfony2 website

« Back to the Plugins Home


Forgot your password?
Create an account



advanced search
Information Readme Releases Changelog Contribute
Show source | Show as Markdown

sfWebBrowser plugin

The sfWebBrowserPlugin proposes an HTTP client capable of making web requests. The interface is similar to that of sfTestBrowser.

Possible uses

  • Querying a Web service
  • Monitoring a Website
  • Mashup of content from several websites
  • Aggregation of RSS feeds
  • ...


This plugin contains one single class: sfWebBrowser. Unit tests are available in the SVN repository, to be placed in a symfony application's test/ directory.


The sfWebBrowser class makes web requests based on a URI:

$b = new sfWebBrowser();
$res = $b->getResponseText();

The usual methods of the sfTestBrowser also work there, with the fluid interface.

// Inline
// More readable




The browser accepts absolute and relative URIs


The get() method accepts parameters either as a query string, or as an array.

$b->get('http://www.example.com/test.php', array('foo', 'bar'));

Requests in POST mode are also supported.

$b->post('http://www.example.com/test.php', array('foo', 'bar'));

You can access the response in various formats, at your convenience:

$myString         = $b->getResponseText();
$myString         = $b->getResponseBody(); // drop the <head> part
$myDomDocument    = $b->getResponseDom();
$myDomCssSelector = $b->getResponseDomCssSelector();
$mySimpleXml      = $b->getResponseXml();

You can also interact with the response with the setFields() and click() methods.


  *>setField('user', 'foobar')

  *>setField('password', 'barbaz')


The browser supports HTTP and HTTPS requests, proxies, redirects, and timeouts.


  • Install the plugin

    $ symfony plugin-install http://plugins.symfony-project.com/sfWebBrowserPlugin

  • Clear the cache to enable the autoloading to find the new class

    $ symfony cc

Known limitations

The web request is made via fopen(), so this will only work if PHP is compiled with sockets support and if allow_url_fopen is defined to true in the php.ini.

Cookies are not handled yet.

Caching is not supported yet.