2011-09-15 19:17:00 +00:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
2011-09-16 09:23:15 +00:00
|
|
|
<!-- $Revision$ -->
|
2011-09-15 19:17:00 +00:00
|
|
|
<chapter xml:id="varnish.examples" xmlns="http://docbook.org/ns/docbook">
|
|
|
|
&reftitle.examples;
|
2011-09-18 14:40:00 +00:00
|
|
|
<section xml:id="varnish.example.admin">
|
2011-09-18 10:38:08 +00:00
|
|
|
<title>Basic VarnishAdmin usage</title>
|
2011-09-15 19:17:00 +00:00
|
|
|
<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 ~ "^/$"');
|
2011-09-18 14:40:00 +00:00
|
|
|
if (VARNISH_STATUS_OK != $status) {
|
2011-09-15 19:17:00 +00:00
|
|
|
throw new VarnishException("Ban method returned $status status\n");
|
|
|
|
}
|
|
|
|
} catch (VarnishException $e) {
|
|
|
|
echo $e->getMessage();
|
|
|
|
exit(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
|
2012-01-10 02:37:08 +00:00
|
|
|
?>
|
2011-09-18 14:40:00 +00:00
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
</section>
|
|
|
|
<section xml:id="varnish.example.stat">
|
|
|
|
<title>Basic VarnishStat usage</title>
|
|
|
|
<para>
|
|
|
|
The example illustrates getting varnish statistic snapshot from shared
|
|
|
|
memory
|
|
|
|
</para>
|
|
|
|
<example>
|
|
|
|
<title>Get statistic snapshot</title>
|
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
|
|
|
|
$vs = new VarnishStat;
|
|
|
|
|
|
|
|
try {
|
|
|
|
$data = $vs->getSnapshot();
|
|
|
|
} catch (VarnishException $e) {
|
|
|
|
echo $e->getMessage();
|
|
|
|
exit(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(0);
|
2012-01-10 02:37:08 +00:00
|
|
|
?>
|
2011-09-18 14:40:00 +00:00
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
</section>
|
|
|
|
<section xml:id="varnish.example.log">
|
|
|
|
<title>Basic VarnishLog usage</title>
|
|
|
|
<para>
|
|
|
|
The example illustrates reading varnish log lines from shared memory
|
|
|
|
</para>
|
|
|
|
<example>
|
|
|
|
<title>Read varnish shared memory log</title>
|
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
|
|
|
|
$vl = new VarnishLog;
|
|
|
|
while(1) {
|
|
|
|
$line = $vl->getLine();
|
|
|
|
printf("%s %d %s", VarnishLog::getTagName($line['tag'], $line['id'],
|
|
|
|
$line['data']);
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(0);
|
2012-01-10 02:37:08 +00:00
|
|
|
?>
|
2011-09-15 19:17:00 +00:00
|
|
|
]]>
|
|
|
|
</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
|
|
|
|
-->
|
|
|
|
|