Configure HTTPlug

If you are using the Symfony bundle you want to use HTTPlug. It is a great tool to decouple from the HTTP client. If you are new to HTTPlug you may want to read their introduction. The very easiest way of using HTTPlug is to install the HTTPlugBundle.

The standard configuration (no configuration) works for a common setup but you may want to add some configuration. If you want to add logging for all the requests and responses for a client named acme you may do:

httplug:
    plugins:
        logger: ~
    clients:
        acme:
            factory: 'httplug.factory.guzzle6'
            plugins: ['httplug.plugin.logger']
            config:
                timeout: 2
                # Set verify to false if somehow you need to disable SSL certificate check.
                # Beware, this should always be true (default value) in production:
                # verify: false

translation:
    http_client: 'httplug.client.acme'

Configure caching

When you are using the auto translation features you may want to cache the responses from your paid third party translator services. To configure HTTPlug to be aggressive for those request you need the CachePlugin and a PSR-6 cache pool.

# Using PHP-cache.com for PSR-6 cache.
cache_adapter:
    providers:
        my_redis:
            factory: 'cache.factory.redis'

httplug:
    plugins:
        logger: ~
        cache:
            cache_pool: 'cache.provider.my_redis'
            config:
                default_ttl: 94608000 # three years
                respect_response_cache_directives: [] # We cache no matter what the server says
    clients:
        translator:
            factory: 'httplug.factory.guzzle6'
            plugins: ['httplug.plugin.cache', 'httplug.plugin.logger']

translation:
    # ...
    http_client: 'httplug.client.translator'
    fallback_translation:
        service: 'google' # 'yandex' is available as an alternative
        api_key: 'foobar'

Note

See PHP-cache.com for information about caching.