Guzzle is a PHP HTTP client and framework for building RESTful web service clients
Pull request Compare This branch is 2435 commits behind guzzle:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Guzzle, PHP HTTP client and webservice framework

Guzzle is a PHP HTTP client and framework for building RESTful web service clients.

  • Extremely powerful API provides all the power of cURL with a simple interface.
  • Truly take advantage of HTTP/1.1 with persistent connections, connection pooling, and parallel requests.
  • Service description DSL allows you build awesome web service clients faster.
  • Symfony2 event-based plugin system allows you to completely modify the behavior of a request.
  • Includes a custom node.js webserver to test your clients.
  • Unit-tested with PHPUnit with 100% code coverage.

Getting started

Installing via Composer

The recommended way to install Guzzle is through Composer.

  1. Add guzzle/guzzle as a dependency in your project's composer.json file:

         "require": {
             "guzzle/guzzle": "*"

    Consider tightening your dependencies to a known version when deploying mission critical applications (e.g. 2.8.*).

  2. Download and install Composer:

     curl -s | php
  3. Install your dependencies:

     php composer.phar install
  4. Require Composer's autoloader

    Composer also prepares an autoload file that's capable of autoloading all of the classes in any of the libraries that it downloads. To use it, just add the following line to your code's bootstrap process:

     require 'vendor/autoload.php';

You can find out more on how to install Composer, configure autoloading, and other best-practices for defining dependencies at


  • Supports GET, HEAD, POST, DELETE, PUT, PATCH, OPTIONS, and any custom verbs
  • Allows full access to request and response headers
  • Persistent connections are implicitly managed by Guzzle, resulting in huge performance benefits
  • Send requests in parallel
  • Cookie sessions can be maintained between requests using the CookiePlugin
  • Allows custom entity bodies, including sending data from a PHP stream and downloading data to a PHP stream
  • Responses can be cached and served from cache using the caching forward proxy plugin
  • Failed requests can be retried using truncated exponential backoff with custom retry policies
  • Entity bodies can be validated automatically using Content-MD5 headers and the MD5 hash validator plugin
  • All data sent over the wire can be logged using the LogPlugin
  • Subject/Observer signal slot system for unobtrusively modifying request behavior
  • Supports all of the features of libcurl including authentication, compression, redirects, SSL, proxies, etc
  • Web service client framework for building future-proof interfaces to web services
  • Includes a service description DSL for quickly building webservice clients
  • Full support for URI templates
  • Advanced batching functionality to efficiently send requests or commands in parallel with customizable batch sizes and transfer strategies

HTTP basics


use Guzzle\Http\Client;

$client = new Client('{{key}}', array(
    'key' => '***'

// Issue a path using a relative URL to the client's base URL
// Sends to***/users
$request = $client->get('users');
$response = $request->send();

// Relative URL that overwrites the path of the base URL
$request = $client->get('/test/123.php?a=b');

// Issue a head request on the base URL
$response = $client->head()->send();
// Delete user 123
$response = $client->delete('users/123')->send();

// Send a PUT request with custom headers
$response = $client->put('upload/text', array(
    'X-Header' => 'My Header'
), 'body of the request')->send();

// Send a PUT request using the contents of a PHP stream as the body
// Send using an absolute URL (overrides the base URL)
$response = $client->put('', array(
    'X-Header' => 'My Header'
), fopen('', 'r'));

// Create a POST request with a file upload (notice the @ symbol):
$request = $client->post('http://localhost:8983/solr/update', null, array (
    'custom_field' => 'my value',
    'file' => '@/path/to/documents.xml'

// Create a POST request and add the POST files manually
$request = $client->post('http://localhost:8983/solr/update')
        'file' => '/path/to/documents.xml'

// Responses are objects
echo $response->getStatusCode() . ' ' . $response->getReasonPhrase() . "\n";

// Requests and responses can be cast to a string to show the raw HTTP message
echo $request . "\n\n" . $response;

// Create a request based on an HTTP message
$request = RequestFactory::fromMessage(
    "PUT / HTTP/1.1\r\n" .
    "Host:\r\n" .
    "Content-Type: text/plain"
    "Transfer-Encoding: chunked\r\n" .
    "\r\n" .
    "this is the body"

Send requests in parallel


try {
    $client = new Guzzle\Http\Client('');
    $responses = $client->send(array(
} catch (Guzzle\Common\Exception\ExceptionCollection $e) {
    echo "The following requests encountered an exception: \n";
    foreach ($e as $exception) {
        echo $exception->getRequest() . "\n" . $exception->getMessage() . "\n";

URI templates

Guzzle supports the entire URI templates RFC.


$client = new Guzzle\Http\Client('', array(
    'path' => '/path/to',
    'a'    => 'hi',
    'data' => array(
        'foo'  => 'bar',
        'mesa' => 'jarjar'

$request = $client->get('{+path}{?a,data*}');

The generated request URL would become:

You can specify URI templates and an array of additional template variables to use when creating requests:


$client = new Guzzle\Http\Client('', array(
    'a' => 'hi'

$request = $client->get(array('/{?a,b}', array(
    'b' => 'there'

The resulting URL would become

Unit testing

Build Status

Guzzle uses PHPUnit for unit testing. In order to run the unit tests, you'll first need to install the dependencies of the project using Composer: php composer.phar install --dev. You can then run the tests using vendor/bin/phpunit or phing test (if you have phing installed).