# Symfony HTTPClient

PHP

Symfony [HttpClient](https://symfony.com/doc/current/components/http_client.html)is a PHP HTTP client that sends HTTP requests and integrates well with web services. Integrating Blackfire with Symfony HttpClient lets you **profile programmatically**your websites, HTTP APIs, or web services.

> **Note**
>
> [Distributed Profiling](../../../profiling-cookbooks/distributed-profiling#distributed-profiling) allows you to trigger sub-profiles automatically, without having to trigger profiles programmatically.

## Installation

Add [Blackfire PHP SDK](../../../php/integrations/sdk#php-sdk-installation) as a dependency in your project (1.19.1+ version).

## Profiling

The Blackfire PHP SDK provides a **Symfony HttpClient decorator** that eases the profiling of requests made via HttpClient:

```php
use Blackfire\Bridge\Symfony\BlackfiredHttpClient;
use Blackfire\Client;
use Blackfire\ClientConfiguration;
use Symfony\Component\HttpClient\HttpClient;

$blackfire = new BlackfireClient(new ClientConfiguration($clientId, $clientToken));

$httpClient = new BlackfiredHttpClient(HttpClient::create(), $blackfire);
```

Whenever you want to profile a request, set the `blackfire` extra option to `true`:

```php
$response = $httpClient->request('GET', 'https://www.symfony.com/blog/', [
    'extra' => [
        'blackfire' => true,
    ],
]);
```

If you execute this script, a profile will be created on your Blackfire account and tests defined in your `.blackfire.yaml` if any will be executed as well.

If you want to better control the profile configuration, like the title of the profile, pass a `\Blackfire\Profile\Configuration` instance as the `blackfire` extra option value:

```php
$config = new \Blackfire\Profile\Configuration();
$config->setTitle('Blog Home');

$response = $httpClient->request('GET', 'https://www.symfony.com/blog/', [
    'extra' => [
        'blackfire' => $config,
    ],
]);
```

Learn more about [profiling configuration settings](../../../php/integrations/sdk#php-sdk-profile-configuration) in the PHP SDK documentation.
