php-doc-en/reference/varnish/examples.xml

82 lines
1.7 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<chapter xml:id="varnish.examples" xmlns="http://docbook.org/ns/docbook">
&reftitle.examples;
<section xml:id="varnish.example">
<title>Basic usage</title>
<para>
The example illustrates a simple usage of the ban functionality
</para>
<example>
<title>Ban an URL</title>
<programlisting role="php">
<![CDATA[
<?php
$args = array(
VARNISH_CONFIG_HOST => "::1",
VARNISH_CONFIG_PORT => 6082,
VARNISH_CONFIG_SECRET => "5174826b-8595-4958-aa7a-0609632ad7ca",
VARNISH_CONFIG_TIMEOUT => 300,
);
$va = new VarnishAdmin($args);
try {
if(!$va->connect()) {
throw new VarnishException("Connection failed\n");
}
} catch (VarnishException $e) {
echo $e->getMessage();
exit(3);
}
try {
if(!$va->auth()) {
throw new VarnishException("Auth failed\n");
}
} catch (VarnishException $e) {
echo $e->getMessage();
exit(3);
}
try {
$status = $va->ban('req.url ~ "^/$"');
if (!VARNISH_STATUS_OK == $status) {
throw new VarnishException("Ban method returned $status status\n");
}
} catch (VarnishException $e) {
echo $e->getMessage();
exit(3);
}
exit(0);
]]>
</programlisting>
</example>
</section>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->