1
0
mirror of https://github.com/php/doc-ja.git synced 2026-03-23 22:52:11 +01:00
Files
archived-doc-ja/reference/varnish/examples.xml
2024-02-11 19:46:17 +09:00

135 lines
2.9 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 73fae4ee51b644b72028e610abefefced57c18ad Maintainer: takagi Status: ready -->
<!-- CREDITS: satoruyoshida -->
<chapter xml:id="varnish.examples" xmlns="http://docbook.org/ns/docbook">
&reftitle.examples;
<section xml:id="varnish.example.admin">
<title>基本的な VarnishAdmin の使用法</title>
<para>
禁止機能の簡単な使用法を示します。
</para>
<example>
<title>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>基本的な VarnishStat の使用法</title>
<para>
共用メモリから、varnish 統計のスナップショットを取得する例を示します。
</para>
<example>
<title>統計のスナップショットを取得する</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>基本的な VarnishLog の使用法</title>
<para>
共用メモリから、varnish のログを読み取る例を示します。
</para>
<example>
<title>varnish の共用メモリログを読み取る</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
-->