|
1 | 1 | Caching Proxy Clients |
2 | 2 | ===================== |
3 | 3 |
|
4 | | -This library ships with clients for the Varnish, NGINX and Symfony built-in caching proxies. You |
5 | | -can use the clients either wrapped by the :doc:`cache invalidator <cache-invalidator>` |
6 | | -(recommended), or directly for low-level access to invalidation functionality. |
| 4 | +This library ships with clients for the Varnish and NGINX caching servers and |
| 5 | +the Symfony built-in HTTP cache. You can use the clients either wrapped by the |
| 6 | +:doc:`cache invalidator <cache-invalidator>` (recommended), or directly for |
| 7 | +low-level access to invalidation functionality. Which client you need depends on |
| 8 | +which caching solution you use. |
7 | 9 |
|
8 | 10 | .. _client setup: |
9 | 11 |
|
10 | 12 | Setup |
11 | 13 | ----- |
12 | 14 |
|
| 15 | +HTTP Adapter Installation |
| 16 | +~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 17 | + |
| 18 | +Because the clients send invalidation requests over HTTP, an `HTTP adapter`_ |
| 19 | +must be installed. Which one you need depends on the HTTP client library that |
| 20 | +you use in your project. For instance, if you use Guzzle 6 in your project, |
| 21 | +install the appropriate adapter: |
| 22 | + |
| 23 | +.. code-block:: bash |
| 24 | +
|
| 25 | + $ composer require php-http/guzzle6-adapter |
| 26 | +
|
| 27 | +You also need a `PSR-7 message implementation`_. If you use Guzzle 6, Guzzle’s |
| 28 | +implementation is already included. If you use another client, install one of |
| 29 | +the implementations. Recommended: |
| 30 | + |
| 31 | +.. code-block:: bash |
| 32 | +
|
| 33 | + $ composer require guzzlehttp/psr7 |
| 34 | +
|
| 35 | +Alternatively: |
| 36 | + |
| 37 | +.. code-block:: bash |
| 38 | +
|
| 39 | + $ composer require zendframework/zend-diactoros |
| 40 | +
|
| 41 | +.. _HTTP adapter configuration: |
| 42 | + |
| 43 | +HTTP Adapter Configuration |
| 44 | +~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 45 | + |
| 46 | +By default, the proxy client will find the adapter that you have installed |
| 47 | +through Composer. But you can also pass the adapter explicitly. This is most |
| 48 | +useful when you have created a HTTP client with custom options or middleware |
| 49 | +(such as logging):: |
| 50 | + |
| 51 | + use GuzzleHttp\Client; |
| 52 | + |
| 53 | + $config = [ |
| 54 | + // For instance, custom middlewares |
| 55 | + ]; |
| 56 | + $yourHttpClient = new Client($config); |
| 57 | + |
| 58 | +Take your client and create a HTTP adapter from it:: |
| 59 | + |
| 60 | + use Http\Adapter\Guzzle6HttpAdapter; |
| 61 | + |
| 62 | + $adapter = new Guzzle6HttpAdapter($client); |
| 63 | + |
| 64 | +Then pass that adapter to the caching proxy client:: |
| 65 | + |
| 66 | + $proxyClient = new Varnish($servers, '/baseUrl', $adapter); |
| 67 | + // Varnish as example, but also possible for NGINX and Symfony |
| 68 | + |
13 | 69 | Varnish Client |
14 | 70 | ~~~~~~~~~~~~~~ |
15 | 71 |
|
@@ -56,9 +112,13 @@ is available as the second parameter:: |
56 | 112 | $nginx = new Nginx($servers, 'my-cool-app.com'); |
57 | 113 |
|
58 | 114 | If you have configured NGINX to support purge requests at a separate location, |
59 | | -supply that location to the class as the third parameter:: |
| 115 | +call `setPurgeLocation()`:: |
| 116 | + |
| 117 | + use FOS\HttpCache\ProxyClient\Nginx; |
| 118 | + |
| 119 | + $nginx = new Nginx($servers, $baseUri); |
| 120 | + $nginx->setPurgeLocation('/purge'); |
60 | 121 |
|
61 | | - $nginx = new Nginx($servers, 'my-cool-app.com', '/purge'); |
62 | 122 |
|
63 | 123 | .. note:: |
64 | 124 |
|
@@ -205,25 +265,5 @@ Varnish client:: |
205 | 265 | Make sure to add any headers that you want to ban on to your |
206 | 266 | :doc:`proxy configuration <proxy-configuration>`. |
207 | 267 |
|
208 | | -.. _custom guzzle client: |
209 | | - |
210 | | -Custom Guzzle Client |
211 | | --------------------- |
212 | | - |
213 | | -By default, the proxy clients instantiate a `Guzzle client`_ to communicate |
214 | | -with the caching proxy. If you need to customize the requests, for example to |
215 | | -send a basic authentication header, you can inject a custom Guzzle client:: |
216 | | - |
217 | | - use FOS\HttpCache\ProxyClient\Varnish; |
218 | | - use Guzzle\Http\Client; |
219 | | - |
220 | | - $client = new Client(); |
221 | | - $client->setDefaultOption('auth', array('username', 'password', 'Digest')); |
222 | | - |
223 | | - $servers = array('10.0.0.1'); |
224 | | - $varnish = new Varnish($servers, '/baseUrl', $client); |
225 | | - |
226 | | -The Symfony client accepts a guzzle client as the 3rd parameter as well, NGINX |
227 | | -accepts it as 4th parameter. |
228 | | - |
229 | | -.. _Guzzle client: http://guzzle3.readthedocs.org/ |
| 268 | +.. _HTTP Adapter: http://php-http.readthedocs.org/en/latest/ |
| 269 | +.. _PSR-7 message implementation: https://packagist.org/providers/psr/http-message-implementation |
0 commit comments