ride / lib-varnish
Varnish library of the Ride framework.
Installs: 20 669
Dependents: 6
Suggesters: 0
Security: 0
Stars: 3
Watchers: 12
Forks: 1
Open Issues: 0
Requires
- ride/lib-log: ^1.0.0
This package is auto-updated.
Last update: 2024-10-13 00:26:14 UTC
README
Varnish library of the PHP Ride framework.
What's In This Library
VarnishServer
The VarnishServer interface is used to manipulate a single Varnish server or a pool of servers transparantly.
VarnishAdmin
The VarnishAdmin class connects to a single Varnish server directly to send commands.
VarnishPool
The VarnishPool class can be used to create a pool of different VarnishAdmin instances. All commands of the VarnishServer interface will be invoked on all available servers in the pool.
Code Sample
Check this code sample to see some of this library's functionality:
<?php use ride\library\varnish\exception\V arnishException; use ride\library\varnish\VarnishAdmin; use ride\library\varnish\VarnishPool; try { // create a single server $varnish = new VarnishAdmin('localhost', 6082, 'your-secret'); // check if worker process is running $varnish->isRunning(); // true | false // start the cache process, this will call isRunning() internally $varnish->start(); // stop the cache process, this will call isRunning() internally $varnish->stop(); // ban with a URL and everything underneath it $varnish->banUrl('http://example.com/path', true); // ban with an expression $varnish->ban('req.http.host == "example.com" && req.url == "/path/to/page"'); // create a pool of servers $pool = new VarnishPool(); $pool->addServer($varnish); $pool->addServer(new VarnishAdmin('example.com', 6082, 'sneaky sneaky'); // ban with a URL or with an expression on all servers $pool->banUrl('http://example.com/path'); $pool->ban('req.http.host == "example.com" && req.url == "/path/to/page"'); } catch (VarnishException $exception) { // something went wrong }
Implementations
For more examples, you can check the following implementations of this library:
Installation
You can use Composer to install this library.
composer require ride/lib-varnish