PHPackages                             m6web/guzzle-http-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. m6web/guzzle-http-bundle

ActiveSymfony-bundle[HTTP &amp; Networking](/categories/http)

m6web/guzzle-http-bundle
========================

Symfony bundle on top of Guzzle

v6.0.0(2y ago)17511.5k↓39.5%9[1 issues](https://github.com/BedrockStreaming/GuzzleHttpBundle/issues)2MITPHPPHP &gt;=8.1

Since Jun 24Pushed 2y ago48 watchersCompare

[ Source](https://github.com/BedrockStreaming/GuzzleHttpBundle)[ Packagist](https://packagist.org/packages/m6web/guzzle-http-bundle)[ RSS](/packages/m6web-guzzle-http-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (14)Versions (61)Used By (2)

GuzzleHttpBundle
================

[](#guzzlehttpbundle)

[![Build Status](https://github.com/BedrockStreaming/GuzzleHttpBundle/actions/workflows/ci.yml/badge.svg)](https://github.com/BedrockStreaming/GuzzleHttpBundle/actions/workflows/ci.yml) [![Latest Stable Version](https://camo.githubusercontent.com/7d78635a43e1e174772903fc708578b3180946041b69ee0d8f28411b5aefaabe/687474703a2f2f706f7365722e707567782e6f72672f6d367765622f67757a7a6c652d687474702d62756e646c652f76)](https://packagist.org/packages/m6web/guzzle-http-bundle) [![Total Downloads](https://camo.githubusercontent.com/2371abaf71b1ea282a1b8e35b8a53f01d937d582bdb389fbc522a7d0dfb76a74/687474703a2f2f706f7365722e707567782e6f72672f6d367765622f67757a7a6c652d687474702d62756e646c652f646f776e6c6f616473)](https://packagist.org/packages/m6web/guzzle-http-bundle) [![License](https://camo.githubusercontent.com/1f5e3bf88201f38b2fa7a6095334e308c49a3fe55498133860b4a9e823611799/687474703a2f2f706f7365722e707567782e6f72672f6d367765622f67757a7a6c652d687474702d62756e646c652f6c6963656e7365)](https://packagist.org/packages/m6web/guzzle-http-bundle) [![PHP Version Require](https://camo.githubusercontent.com/1cd4b9a2b465bfe7a71689b01e51743fe73abbe5517cfe5eef83beeacb21d0f1/687474703a2f2f706f7365722e707567782e6f72672f6d367765622f67757a7a6c652d687474702d62756e646c652f726571756972652f706870)](https://packagist.org/packages/m6web/guzzle-http-bundle)

The GuzzleHttpBundle provide Guzzle clients as Symfony services.

Installation
------------

[](#installation)

Require the bundle with Composer:

```
$ composer require m6web/guzzle-http-bundle
```

> For older Symfony versions, you can try to install an older version of this bundle.

If you don't use Symfony Flex, register the bundle in your kernel:

```
return [
    // ...
    M6Web\Bundle\GuzzleHttpBundle\M6WebGuzzleHttpBundle => ['all' => true],
]
```

Usage
-----

[](#usage)

Add the `m6web_guzzlehttp` section in your configuration file. Here is the minimal configuration required.

```
# app/config/config.yml
m6web_guzzlehttp:
    clients:
        default: ~
        other:
            base_uri: "http://domain.tld/"
```

All subkey under clients defines an instance of guzzle http client. These services are named `m6web_guzzlehttp_`+subkey expect for the `default` subkey that define the main service `m6web_guzzlehttp`.

Then you can ask container for your client:

```
// in a controller

$client = $this->get('m6web_guzzlehttp'); // default client

try {
    $response = $client->get('http://domain.tld/path/to/resource');

    $promises = [
        'first' => $client->getAsync('http://domain.tld/path/to/resource'),
        'second' => $client->getAsync('http://domain.tld/path/to/other/resource')
    ];

    $result = \GuzzleHttp\Promise\Utils::unwrap($promises);
} catch(\GuzzleHttp\Exception\ConnectException $e) {
    // connection problem like timeout
}

// use other client
$otherClient = $this->get('m6web_guzzlehttp_other');
$response = $otherClient->get('path/to/resource'); // call http://domain.tld/path/to/resource
```

The service return a configured guzzle client, for more information on how to use it, you can read the [guzzle6 documentation](http://guzzle.readthedocs.org/en/latest/index.html).

The only difference with guzzle6 reside in usage of curl for the redirect responses. You can choose to have the guzzle behavior for redirection by setting the configuration key `redirect_handler` to `guzzle`.

When a cache system is available, you can use `cache_force` and `cache_ttl` in addition of guzzle options than respectively force clear cache before request and use a specific ttl to a request that override configuration.

```
$client = $this->get('m6web_guzzlehttp');

$response = $client->get('http://domain.tld', ['cache_force' => true]); // remove cache entry and set a new one

$response = $client->get('http://doamin.tld/path', ['cache_ttl' => 200]); // set ttl to 200 seconds instead the default one
```

DataCollector
-------------

[](#datacollector)

A data collector is available when the Symfony profiler is enabled.

It allows you to inspect the following data:

- Method
- Url
- Response code and reason
- Execution time
- Redirect count
- Redirect time
- Cache hit
- Cache TTL

**NOTE:** If you choose Guzzle for `redirect_handler`, The redirect count and redirect time will always be zero. Cache information are available when a cache system is set.

Cache system
------------

[](#cache-system)

You can set a cache for request by adding in the config the `guzzlehttp_cache` with `service` subkey who is a reference to a service implementing `M6Web\Bundle\GuzzleHttpBundle\Cache\CacheInterface`

```
# app/config/config.yml
m6web_guzzlehttp:
    clients:
        default:
            base_uri: "http://domain.tld/"
            guzzlehttp_cache:
                service: my_cache_service
```

We provide an "In memory" cache class that you can use by defining a new cache service and use it in Guzzle configuration:

```
# app/config/config.yml
services:
    company.guzzle.cache.inmemory:
        class: M6Web\Bundle\GuzzleHttpBundle\Cache\InMemory

m6web_guzzlehttp:
    clients:
        default:
            guzzlehttp_cache:
                service: company.guzzle.cache.inmemory
```

We also provide a cache interface for Redis with [our RedisBundle](https://github.com/M6Web/RedisBundle) &gt;= 2.4, than you can use in this way:

```
# app/config/config.yml
m6web_guzzlehttp:
    clients:
        default:
            base_uri: "http://domain.tld/"
            guzzlehttp_cache:
                service: m6_redis.guzzlehttp

m6_redis:
    servers:
        default:
            ip:   '127.0.0.1'
            port: 6379
    clients:
        guzzlehttp:
            servers:   ["default"]     # list of servers to use
            namespace: GuzzleHttp\
            timeout:   2               # timeout in second
            readwritetimeout: 2        # read-write timeout in second
            class: M6Web\Bundle\RedisBundle\CacheAdapters\M6WebGuzzleHttp
```

For more information on how to set up the RedisBundle, refer to the README in the project.

We provide also the same cache system for APCU through the [ApcuBundle](https://github.com/M6Web/ApcuBundle).

Configuration reference
-----------------------

[](#configuration-reference)

As some configuration options accept multiples data types, all services references must start with a `@` character.

```
m6web_guzzlehttp:
    clients_share_the_same_handler: false          # Use "true" if you want all your clients to share the same Guzzle handler. It means that your different clients will be able to send asynchronous requests altogether.
    clients:
        default:
            base_uri: ""                           # Base uri to prepend on request uri
            timeout: 5.0                           # request timeout
            http_errors: true                      # Use "false" to disable throwing exceptions on HTTP protocol errors
            redirect_handler: curl                 # guzzle or curl
            guzzlehttp_cache:                      # optional cache
                cache_server_errors: true          # at false, no server errors will be cached
                cache_client_errors: true          # at false, no client errors will be cached
                default_ttl: 3600                  # default ttl for cache entry in seconds
                ignore_cache_errors: false         # if true, no exception would be thrown when cache is unavailable
                use_header_ttl: false              # use the cache-control header to set the ttl
                service: '@my_cache_service'       # reference to service who implements the cache interface
            headers:                               # optional. Default request headers
                User_Agent: "m6web/1.0"            # set header "User-Agent" with the value "m6web/1.0"
                header\_name: "my value"           # set header "header_name" with value "my value"
            auth: ["user", "password"]             # optional, http auth user and password
            allow_redirects:                       # false to disallow redirection or an array describing the redirect behavior of a request
                max: 5                             # Maximum redirect to follow
                strict: false                      # use "strict" RFC compliant redirects. (guzzle redirect handler only)
                referer: true                      # add a Referer header
                protocols: ['http', 'https']       # restrict redirect to a protocol
            body: '@my.body.service'               # string | service reference, request body
            cert: ['/path/to/.pem', 'password']    # string | array, Set to a string to specify client side certificate, an array if a password is required
            cookies:                               # boolean | array, false disable cookies
                -
                    name: "bar"
                    value: "foo"
                    domain: "foobar.com"
                    path: "/my/path"
                    max: 100
                    expires: null
                    secure: false
                    discard: false
                    httpOnly: false
                    max-age: null
                -
                    name: tracker
                    value: tracker
            connect_timeout: 1                     # float, Float describing the number of seconds to wait while trying to connect to a server
            debug: true                            # boolean, Set to true to enable debug output with the handler used to send a request
            decode_content: true                   # string | boolean, specify whether Content-Encoding responses are automatically decoded
            delay: 10                              # boolean | float, the number of milliseconds to delay before sending the request
            expect: true                           # boolean | integer, controls the behavior of the "Expect: 100-Continue" header
            force_ip_resolve:                      # Set to "v4" if you want the HTTP handlers to use only ipv4 protocol or "v6" for ipv6 protocol.
            form_params:                           # array, Used to send an application/x-www-form-urlencoded POST request.
                foo: 'bar'
                bar: 'foo'
            json: [ foo: 'bar' ]                   # mixed, the json option is used to easily upload JSON encoded data as the body of a request
            multipart:                             # array, Sets the body of the request to a multipart/form-data form.
                -
                    name: 'foo'
                    contents: 'bar'
                    headers:
                        X-foo: 'bar'
                        X-bar: 'foo'
            on_headers: '@invokable.service.id'    # A callable that is invoked when the HTTP headers of the response have been received
            on_stats: '@invokable.service.id'      # on_stats allows you to get access to transfer statistics
            proxy:                                 # string | array, Pass a string to specify an HTTP proxy, or an array to specify different proxies for different protocols.
                http: 'tcp://localhost:8125'
            query:                                 # array, Associative array of query string values or query string to add to the request.
                foo: 'bar'
                bar: 'foo'
            sink: '/path/to/file'                  # String or Psr\Http\Message\StreamInterface service, Specify where the body of a response will be saved.
            ssl_key: ['/path/to/.pem', 'password'] # string | array, Specify the path to a file containing a private SSL key in PEM format.
            stream: true                           # Boolean, Set to true to stream a response rather than download it all up-front.
            synchronous: true                      # Boolean, Set to true to inform HTTP handlers that you intend on waiting on the response. This can be useful for optimizations.
            verify: true                           # Boolean Describes the SSL certificate verification behavior of a request.
            version: 1.0                           # String Protocol version to use with the request.

        otherclient:
            ...
```

For the `headers` options, the key in array represent the header name. The underscore will be transformed to hyphen except if it's escaped by a backslash.

Adding a middleware
-------------------

[](#adding-a-middleware)

Implement `M6Web\Bundle\GuzzleHttpBundle\Middleware\MiddlewareInterface`.

Tag your service with `m6web_guzzlehttp.middleware` and specify the client as follows:

```
Acme\Infra\GraphQL\Client\MyMiddleware:
        tags:
            - {name: 'm6web_guzzlehttp.middleware', client: 'myclient' }

```

Contributing
------------

[](#contributing)

First, thank you for contributing!

Here are few rules to follow for an easier code review before the maintainers accept and merge your pull request:

- you MUST write or update tests
- you MUST write or update documentation
- the CI must pass on your pull request

Running the test
----------------

[](#running-the-test)

Install the composer dev dependencies

```
make install
```

Then run the test with [atoum](https://github.com/atoum/atoum) unit test framework

```
make test
```

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity45

Moderate usage in the ecosystem

Community35

Small or concentrated contributor base

Maturity86

Battle-tested with a long release history

 Bus Factor4

4 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~55 days

Recently: every ~93 days

Total

56

Last Release

936d ago

Major Versions

v1.7.0 → v2.0.02016-06-09

v2.4.2 → v3.0.02019-12-18

v3.1.0 → v4.0.02021-12-09

v4.1.0 → v5.0.02022-04-05

v5.1.1 → v6.0.02023-10-26

PHP version history (5 changes)v1.0.0PHP &gt;=5.5

v2.1.5PHP &gt;=7.0

v3.0.0PHP &gt;=7.1

v4.0.0PHP &gt;=7.4

v6.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2069361?v=4)[Patrick](/maintainers/Bedrock)[@Bedrock](https://github.com/Bedrock)

![](https://avatars.githubusercontent.com/u/5878620?v=4)[Fabien de Saint pern](/maintainers/fabdsp)[@fabdsp](https://github.com/fabdsp)

![](https://avatars.githubusercontent.com/u/5537799?v=4)[Benoit](/maintainers/b-viguier)[@b-viguier](https://github.com/b-viguier)

---

Top Contributors

[![omansour](https://avatars.githubusercontent.com/u/1131098?v=4)](https://github.com/omansour "omansour (23 commits)")[![t-geindre](https://avatars.githubusercontent.com/u/6348039?v=4)](https://github.com/t-geindre "t-geindre (13 commits)")[![jdecool](https://avatars.githubusercontent.com/u/433926?v=4)](https://github.com/jdecool "jdecool (12 commits)")[![Oliboy50](https://avatars.githubusercontent.com/u/2571084?v=4)](https://github.com/Oliboy50 "Oliboy50 (7 commits)")[![mojoLyon](https://avatars.githubusercontent.com/u/797786?v=4)](https://github.com/mojoLyon "mojoLyon (6 commits)")[![shavounet](https://avatars.githubusercontent.com/u/2323369?v=4)](https://github.com/shavounet "shavounet (5 commits)")[![macintoshplus](https://avatars.githubusercontent.com/u/814683?v=4)](https://github.com/macintoshplus "macintoshplus (3 commits)")[![GautierLB](https://avatars.githubusercontent.com/u/2836000?v=4)](https://github.com/GautierLB "GautierLB (3 commits)")[![fabdsp](https://avatars.githubusercontent.com/u/5878620?v=4)](https://github.com/fabdsp "fabdsp (3 commits)")[![titoko](https://avatars.githubusercontent.com/u/1798254?v=4)](https://github.com/titoko "titoko (2 commits)")[![COil](https://avatars.githubusercontent.com/u/177844?v=4)](https://github.com/COil "COil (2 commits)")[![Fabex](https://avatars.githubusercontent.com/u/1540419?v=4)](https://github.com/Fabex "Fabex (2 commits)")[![hdetang](https://avatars.githubusercontent.com/u/93374225?v=4)](https://github.com/hdetang "hdetang (2 commits)")[![lucascourot](https://avatars.githubusercontent.com/u/938375?v=4)](https://github.com/lucascourot "lucascourot (2 commits)")[![mikaelrandy](https://avatars.githubusercontent.com/u/187703?v=4)](https://github.com/mikaelrandy "mikaelrandy (2 commits)")[![bcoppin](https://avatars.githubusercontent.com/u/6584705?v=4)](https://github.com/bcoppin "bcoppin (2 commits)")[![Keenegan](https://avatars.githubusercontent.com/u/3308307?v=4)](https://github.com/Keenegan "Keenegan (1 commits)")[![jubianchi](https://avatars.githubusercontent.com/u/327237?v=4)](https://github.com/jubianchi "jubianchi (1 commits)")[![pgrimaud](https://avatars.githubusercontent.com/u/1866496?v=4)](https://github.com/pgrimaud "pgrimaud (1 commits)")[![raf262](https://avatars.githubusercontent.com/u/24521850?v=4)](https://github.com/raf262 "raf262 (1 commits)")

---

Tags

httpphpsymfony-bundlehttpclientbundlehttp client

###  Code Quality

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/m6web-guzzle-http-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/m6web-guzzle-http-bundle/health.svg)](https://phpackages.com/packages/m6web-guzzle-http-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[php-http/httplug-bundle

Symfony integration for HTTPlug

38921.0M54](/packages/php-http-httplug-bundle)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
