PHPackages                             tourze/http-client-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. tourze/http-client-bundle

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

tourze/http-client-bundle
=========================

HTTP Client Bundle

1.1.0(6mo ago)013.7k20MITPHPCI passing

Since Apr 7Pushed 5mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (52)Versions (17)Used By (20)

HttpClientBundle
================

[](#httpclientbundle)

[English](README.md) | [中文](README.zh-CN.md)

[![PHP Version](https://camo.githubusercontent.com/ee631d1b3535e8b3a99c9152d465e9db0c74b77d6c84694515f8ebc38cda9aea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d626c75653f7374796c653d666c61742d737175617265)](https://php.net)[![Symfony Version](https://camo.githubusercontent.com/e42e7a9cf14b1978c043ea01b328af520235ef3fe9d7f0431f2a58c063cea9a7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73796d666f6e792d253545362e342d677265656e3f7374796c653d666c61742d737175617265)](https://symfony.com)[![License](https://camo.githubusercontent.com/c090e080484e2a2bc766446291d04437db823929042bf614b26a1643660ddf6f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e3f7374796c653d666c61742d737175617265)](LICENSE)\[[![Build Status](https://camo.githubusercontent.com/1ecc7fce0a7f4c4d1a8585ee7efb83d13cdf602805965f7f6f1910c0eb2c2648/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f746f75727a652f687474702d636c69656e742d62756e646c652f43493f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/1ecc7fce0a7f4c4d1a8585ee7efb83d13cdf602805965f7f6f1910c0eb2c2648/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f746f75727a652f687474702d636c69656e742d62756e646c652f43493f7374796c653d666c61742d737175617265)\] () \[[![Code Coverage](https://camo.githubusercontent.com/adda5b34586fae74889a2bfad5b343f32f2ff899fc7a5fd588a126db4ae26323/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f75727a652f687474702d636c69656e742d62756e646c653f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/adda5b34586fae74889a2bfad5b343f32f2ff899fc7a5fd588a126db4ae26323/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f75727a652f687474702d636c69656e742d62756e646c653f7374796c653d666c61742d737175617265)\] ()

A powerful Symfony HTTP client bundle with smart implementation selection, request caching, distributed locking, retry mechanisms, detailed logging, coroutine support, DNS cache, async requests, and event-driven extensibility.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Configuration](#configuration)
- [Dependencies](#dependencies)
- [Advanced Usage](#advanced-usage)
- [Security](#security)
- [Documentation](#documentation)
- [Contribution](#contribution)
- [License](#license)

Features
--------

[](#features)

- Smart HTTP client with auto-selection of best implementation (curl/native)
- Request caching for efficient API data retrieval
- Distributed lock to prevent duplicate requests
- Automatic retry mechanisms for transient errors
- Full request/response logging with detailed metrics
- Coroutine support (prevents curl instance sharing)
- DNS resolution caching for improved performance
- Asynchronous request support with event-driven architecture
- Event system for request/response hooks and middleware
- SSL certificate validation and health checks

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

[](#installation)

### Requirements

[](#requirements)

- PHP &gt;= 8.1
- Symfony &gt;= 6.4

### Install via Composer

[](#install-via-composer)

```
composer require tourze/http-client-bundle
```

Quick Start
-----------

[](#quick-start)

### 1. Enable the Bundle

[](#1-enable-the-bundle)

Add to `config/bundles.php`:

```
return [
    // ... other bundles
    HttpClientBundle\HttpClientBundle::class => ['all' => true],
];
```

### 2. Create an API Client

[](#2-create-an-api-client)

```
use HttpClientBundle\Client\ApiClient;
use HttpClientBundle\Request\RequestInterface;

class MyApiClient extends ApiClient
{
    protected function getRequestUrl(RequestInterface $request): string
    {
        return 'https://api.example.com/' . $request->getRequestPath();
    }

    protected function getRequestMethod(RequestInterface $request): string
    {
        return $request->getRequestMethod() ?? 'GET';
    }
}
```

### 3. Create Request Classes

[](#3-create-request-classes)

#### Basic Request

[](#basic-request)

```
use HttpClientBundle\Request\RequestInterface;

class MyApiRequest implements RequestInterface
{
    public function __construct(private string $path) {}

    public function getRequestPath(): string
    {
        return $this->path;
    }

    public function getRequestOptions(): ?array
    {
        return ['timeout' => 30];
    }

    public function getRequestMethod(): ?string
    {
        return 'GET';
    }
}
```

#### Cached Request

[](#cached-request)

```
use HttpClientBundle\Request\CacheRequest;

class CachedApiRequest implements RequestInterface, CacheRequest
{
    public function getCacheKey(): string
    {
        return 'api-cache-' . md5($this->getRequestPath());
    }

    public function getCacheDuration(): int
    {
        return 3600; // 1 hour
    }
}
```

Configuration
-------------

[](#configuration)

### Basic Configuration

[](#basic-configuration)

```
# config/packages/http_client_bundle.yaml
http_client:
    logging:
        enabled: true
        persist_days: 7
    cache:
        default_ttl: 3600
    lock:
        timeout: 30
    retry:
        max_attempts: 3
        delay: 1000
```

### Service Configuration

[](#service-configuration)

```
# config/services.yaml
services:
    app.my_api_client:
        class: App\Client\MyApiClient
        arguments:
            $httpClient: '@http_client_bundle.smart_http_client'
            $cache: '@cache.app'
            $lockFactory: '@lock.factory'
```

Dependencies
------------

[](#dependencies)

This bundle depends on several core packages:

### Core Dependencies

[](#core-dependencies)

- `symfony/http-client`: HTTP client implementation
- `symfony/cache`: Caching functionality
- `symfony/lock`: Distributed locking
- `symfony/event-dispatcher`: Event system
- `doctrine/orm`: Entity persistence
- `psr/log`: Logging interface

### Optional Dependencies

[](#optional-dependencies)

- `tourze/symfony-aop-async-bundle`: Async request support
- `tourze/doctrine-async-bundle`: Async database operations
- `spatie/ssl-certificate`: SSL certificate validation

Advanced Usage
--------------

[](#advanced-usage)

### Health Checks

[](#health-checks)

The bundle provides built-in health check functionality:

```
class MyApiClient extends ApiClient implements CheckInterface
{
    public function check(): ResultInterface
    {
        // Automatic SSL and connectivity checks
        return parent::check();
    }
}
```

### Event Listeners

[](#event-listeners)

```
use HttpClientBundle\Event\RequestEvent;
use HttpClientBundle\Event\ResponseEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class ApiEventSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            RequestEvent::class => 'onRequest',
            ResponseEvent::class => 'onResponse',
        ];
    }

    public function onRequest(RequestEvent $event): void
    {
        // Add authentication headers
        $options = $event->getOptions();
        $options['headers']['Authorization'] = 'Bearer ' . $this->getToken();
        $event->setOptions($options);
    }

    public function onResponse(ResponseEvent $event): void
    {
        // Log response metrics
        $this->logger->info('API Response', [
            'status_code' => $event->getResponse()->getStatusCode(),
            'duration' => $event->getDuration(),
        ]);
    }
}
```

### Coroutine-Safe Usage

[](#coroutine-safe-usage)

For use with Swoole or ReactPHP:

```
use HttpClientBundle\Client\CoroutineSafeHttpClient;

class MyCoroutineApiClient extends ApiClient
{
    protected function createHttpClient(): HttpClientInterface
    {
        return new CoroutineSafeHttpClient($this->getInnerHttpClient());
    }
}
```

Security
--------

[](#security)

### SSL Certificate Validation

[](#ssl-certificate-validation)

The bundle automatically validates SSL certificates:

```
// Automatic SSL validation in health checks
$result = $apiClient->check();
if ($result instanceof Success) {
    // SSL certificate is valid
}
```

### Request Signing

[](#request-signing)

Implement request signing for API security:

```
class SignedApiRequest implements RequestInterface
{
    public function getRequestOptions(): ?array
    {
        $timestamp = time();
        $signature = hash_hmac('sha256', $this->getBody() . $timestamp, $this->secretKey);

        return [
            'headers' => [
                'X-Timestamp' => $timestamp,
                'X-Signature' => $signature,
            ],
        ];
    }
}
```

### Rate Limiting

[](#rate-limiting)

Use distributed locks for rate limiting:

```
class RateLimitedRequest implements RequestInterface, LockRequest
{
    public function getLockKey(): string
    {
        return 'rate_limit_' . $this->getUserId();
    }
}
```

Documentation
-------------

[](#documentation)

- [API Reference](docs/api.md): Complete API documentation
- [Configuration Guide](docs/configuration.md): Detailed configuration options
- [Performance Tuning](docs/performance.md): Optimization guidelines
- [Troubleshooting](docs/troubleshooting.md): Common issues and solutions

Contribution
------------

[](#contribution)

1. Fork the repository and create a feature branch
2. Write tests for new functionality
3. Ensure all tests pass: `vendor/bin/phpunit`
4. Check code quality: `vendor/bin/phpstan analyse`
5. Submit a pull request with clear description

### Development Setup

[](#development-setup)

```
git clone https://github.com/tourze/http-client-bundle
cd http-client-bundle
composer install
vendor/bin/phpunit
```

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) file for details.

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for version history and upgrade notes.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance71

Regular maintenance activity

Popularity19

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~14 days

Recently: every ~37 days

Total

16

Last Release

188d ago

Major Versions

0.1.8 → 1.0.02025-11-01

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (3 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-http-client-bundle/health.svg)

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

###  Alternatives

[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[sylius/sylius

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

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

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[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)

PHPackages © 2026

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