<?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.admin"> <title>Basic VarnishAdmin 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> <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); ?> ]]> </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); ?> ]]> </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 -->