Skip to content

verafirmansyah/Buzz

 
 

Repository files navigation

Buzz - Scripted HTTP browser

Build Status Latest Version Code Coverage Quality Score Total Downloads Monthly Downloads

Buzz is a lightweight (<1000 lines of code) PHP 7.1 library for issuing HTTP requests.

Installation

Package available on Composer.

Install by running:

composer require kriswallsmith/buzz

Usage

This page will just show you the basics, please read the full documentation.

$client = new Buzz\Client\FileGetContents(new Psr17ResponseFactory());
$browser = new Buzz\Browser($client, new Psr17RequestFactory());
$response = $browser->get('http://www.google.com');

echo $browser->getLastRequest()."\n";
// $response is a PSR-7 object. 
echo $response->getStatusCode(); 

You can also use the low-level HTTP classes directly.

$request = new PSR7Request('GET', 'https://google.com/foo');

$client = new Buzz\Client\FileGetContents(new Psr17ResponseFactory());
$response = $client->send($request, ['timeout' => 4]);

echo $response->getStatusCode();

The Idea of Buzz

Buzz was created by Kris Wallsmith back in 2010. The project grown very popular over the years with more than 7 million downloads.

Since August 2017 Tobias Nyholm is maintaining this library. The idea of Buzz will still be the same, we should have a simple API and mimic browser behavior for easy testing. We should not reinvent the wheel and we should not be as powerful and flexible as other clients (ie Guzzle). We do, however, take performance very seriously.

We do love PSRs and this is a wish list of what PSR we would like to support:

  • PSR-1 (Code style)
  • PSR-2 (Code style)
  • PSR-4 (Auto loading)
  • PSR-7 (HTTP messages)
  • PSR-17 (HTTP factories)
  • PSR-18 (HTTP client)

Backwards Compatibility Promise

We take backwards compatibility very seriously as you should do with any open source project. We strictly follow Semver. Please note that Semver works a bit different prior version 1.0.0. Minor versions prior 1.0.0 are allow to break backwards compatibility.

Being greatly inspired by Symfony's bc promise, we have adopted their method of deprecating classes, interfaces and functions.

Running the tests

There are 2 kinds of tests for this library; unit tests and integration tests. They can be run separably by:

./vendor/bin/simple-phpunit --testsuite Unit
./vendor/bin/simple-phpunit --testsuite Integration

The integration tests makes real HTTP requests to a webserver. There are two different webservers used by our integration tests. A real Nginx server and PHP's built in webserver. The tests that runs with PHP's webserver are provided by php-http/client-integration-tests.

To start the server, open terminal A and run:

./vendor/bin/http_test_server

The other type of integration tests are using Nginx. We use Docker to start the Nginx server.

docker build -t buzz/tests .
docker run -d -p 127.0.0.1:8080:80 buzz/tests

You are now ready to run the integration tests

./vendor/bin/simple-phpunit --testsuite Integration

About

PHP's lightweight HTTP client

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 99.8%
  • Dockerfile 0.2%