ride/lib-varnish

Ride框架的Varnish库。

1.0.2 2017-10-10 14:47 UTC

This package is auto-updated.

Last update: 2024-09-13 00:07:05 UTC


README

PHP Ride框架的Varnish库。

库中包含的内容

VarnishServer

VarnishServer 接口用于透明地操作单个Varnish服务器或服务器池。

VarnishAdmin

VarnishAdmin 类通过直接连接到单个Varnish服务器来发送命令。

VarnishPool

VarnishPool 类可用于创建一个包含不同 VarnishAdmin 实例的池。所有 VarnishServer 接口的命令都将在该池中所有可用的服务器上调用。

代码示例

查看此代码示例以了解此库的一些功能。

<?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
}

实现

要获取更多示例,您可以查看此库的以下实现。

安装

您可以使用 Composer 来安装此库。

composer require ride/lib-varnish