예제 #1
0
                $Sock->connect($timeout);
                $Sock->purge($purge);
                $purges[$host . ':' . $port] = 'Purged';
            } catch (Exception $Ex) {
                $purges[$host . ':' . $port] = 'Error: ' . $Ex->getMessage();
            }
        }
    } else {
        if (isset($postdata['wpv_ping'])) {
            $pingclients = $postdata['wpv_clients'];
            $pingsecret = $postdata['wpv_secret'];
            $timeout = $postdata['wpv_timeout'] or $timeout = 3;
            foreach (wpv_get_clients($pingclients) as $client) {
                list($host, $port, $vers) = $client;
                try {
                    $Sock = wpv_admin_socket($host, $port, $vers);
                    $Sock->set_auth(rawurldecode($pingsecret));
                    @$Sock->connect($timeout);
                    $ping[$host . ':' . $port] = $Sock->status() ? 'Running :)' : 'Stopped, but responding';
                } catch (Exception $Ex) {
                    $ping[$host . ':' . $port] = 'Error: ' . $Ex->getMessage();
                }
            }
        }
    }
}
// get current raw clients string setting
$enabled = get_option('wpv_enabled');
$clients = get_option('wpv_clients', '127.0.0.1:6082 2.1');
$secrets = get_option('wpv_secrets', '');
// get current hostpattern setting
예제 #2
0
/**
 * Send multiple purge commands to all varnishadm sockets
 */
function wpv_purge_urls(array $urls)
{
    $hostpattern = get_option('wpv_host_pattern', '');
    $secrets = wpv_get_secrets();
    $clients = wpv_get_clients();
    if (!$clients) {
        return;
    }
    // iterate over all available sockets
    foreach ($clients as $i => $client) {
        try {
            list($host, $port, $vers) = $client;
            $Sock = wpv_admin_socket($host, $port, $vers);
            if (!empty($secrets[$i])) {
                $Sock->set_auth($secrets[$i]);
            }
            $Sock->connect();
            if (!$Sock->status()) {
                throw new Exception(sprintf('Varnish server stopped on host %s:%d', $host, $port));
            }
            // iterate over all URLs and purge from this socket
            foreach ($urls as $url => $bool) {
                try {
                    $expr = sprintf('req.url ~ "%s"', $url);
                    if ($hostpattern) {
                        $expr .= sprintf(' && req.http.host ~ "%s"', $hostpattern);
                    }
                    $Sock->purge($expr);
                } catch (Exception $Ex) {
                    trigger_error($Ex->getMessage(), E_USER_WARNING);
                    continue;
                }
            }
        } catch (Exception $Ex) {
            trigger_error($Ex->getMessage(), E_USER_WARNING);
        }
        // next socket
        $Sock->quit();
    }
    return true;
}