/php/inclued.examples-implementation.html
HTML | 95 lines | 88 code | 7 blank | 0 comment | 0 complexity | 9b54e6e5798d4cc90690c74f330c2fe8 MD5 | raw file
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="content-type" content="text/html; charset=UTF-8">
- <title>Example that implements inclued into an application</title>
- </head>
- <body><div class="manualnavbar" style="text-align: center;">
- <div class="prev" style="text-align: left; float: left;"><a href="inclued.examples.html">范例</a></div>
- <div class="next" style="text-align: right; float: right;"><a href="ref.inclued.html">inclued 函数</a></div>
- <div class="up"><a href="inclued.examples.html">范例</a></div>
- <div class="home"><a href="index.html">PHP Manual</a></div>
- </div><hr /><div id="inclued.examples-implementation" class="section">
- <h2 class="title">Example that implements inclued into an application</h2>
- <p class="para">
- This example demonstrates the process of implementing inclued into
- an existing application, and viewing the results.
- </p>
- <p class="para">
- <div class="example" id="example-414">
- <p><strong>Example #1 Getting the data within the PHP application itself (function)</strong></p>
- <div class="example-contents">
- <div class="phpcode"><code><span style="color: #000000">
- <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// File to store the inclued information<br /></span><span style="color: #0000BB">$fp </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'/tmp/wp.ser'</span><span style="color: #007700">, </span><span style="color: #DD0000">'w'</span><span style="color: #007700">);<br />if (</span><span style="color: #0000BB">$fp</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">$clue </span><span style="color: #007700">= </span><span style="color: #0000BB">inclued_get_data</span><span style="color: #007700">();<br /> if (</span><span style="color: #0000BB">$clue</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #0000BB">serialize</span><span style="color: #007700">(</span><span style="color: #0000BB">$clue</span><span style="color: #007700">));<br /> }<br /> </span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?></span>
- </span>
- </code></div>
- </div>
- </div>
- </p>
- <p class="para">
- Now that some data exists, it's time to make sense of it in the form of
- a graph. The inclued extension includes a PHP file named
- <var class="filename">gengraph.php</var> that creates a dot file that
- requires the <a href="http://www.graphviz.org/" class="link external">» graphviz</a> library.
- However, this form is not required.
- </p>
- <p class="para">
- <div class="example" id="example-415">
- <p><strong>Example #2 Example use of gengraph.php</strong></p>
- <div class="example-contents"><p>
- This example creates an image named inclued.png that
- shows the inclued data.
- </p></div>
- <div class="example-contents">
- <div class="shellcode"><pre class="shellcode"># First, create the dot file
- $ php gengraph.php -i /tmp/wp.ser -o wp.dot
- # Next, create the image
- $ dot -Tpng -o inclued.png wp.dot</pre>
- </div>
- </div>
- </div>
- </p>
- <p class="para">
- <div class="example" id="example-416">
- <p><strong>Example #3 Listing data via inclued dumps (configuration)</strong></p>
- <div class="example-contents"><p>
- When using the <a href="inclued.configuration.html#ini.inclued.dumpdir" class="link">inclued.dumpdir</a>
- directive, files (include clues) are dumped with every request. Here's one
- way to list those files, and <span class="function"><a href="function.unserialize.html" class="function">unserialize()</a></span> them.
- </p></div>
- <div class="example-contents">
- <div class="phpcode"><code><span style="color: #000000">
- <span style="color: #0000BB"><?php<br />$path </span><span style="color: #007700">= </span><span style="color: #0000BB">ini_get</span><span style="color: #007700">(</span><span style="color: #DD0000">'inclued.dumpdir'</span><span style="color: #007700">);<br />if (</span><span style="color: #0000BB">$path </span><span style="color: #007700">&& </span><span style="color: #0000BB">is_dir</span><span style="color: #007700">(</span><span style="color: #0000BB">$path</span><span style="color: #007700">)) {<br /><br /> echo </span><span style="color: #DD0000">"Path: </span><span style="color: #0000BB">$path</span><span style="color: #DD0000">"</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /> </span><span style="color: #0000BB">$inclues </span><span style="color: #007700">= new </span><span style="color: #0000BB">GlobIterator</span><span style="color: #007700">(</span><span style="color: #0000BB">$path </span><span style="color: #007700">. </span><span style="color: #0000BB">DIRECTORY_SEPARATOR </span><span style="color: #007700">. </span><span style="color: #DD0000">'inclued*'</span><span style="color: #007700">);<br /><br /> if (</span><span style="color: #0000BB">$inclues</span><span style="color: #007700">-></span><span style="color: #0000BB">count</span><span style="color: #007700">() === </span><span style="color: #0000BB">0</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">'No clues today'</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /> exit;<br /> }<br /><br /> foreach (</span><span style="color: #0000BB">$inclues </span><span style="color: #007700">as </span><span style="color: #0000BB">$inclue</span><span style="color: #007700">) {<br /><br /> echo </span><span style="color: #DD0000">'Inclued file: '</span><span style="color: #007700">, </span><span style="color: #0000BB">$inclue</span><span style="color: #007700">-></span><span style="color: #0000BB">getFilename</span><span style="color: #007700">(), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /> </span><span style="color: #0000BB">$data </span><span style="color: #007700">= </span><span style="color: #0000BB">file_get_contents</span><span style="color: #007700">(</span><span style="color: #0000BB">$inclue</span><span style="color: #007700">-></span><span style="color: #0000BB">getPathname</span><span style="color: #007700">());<br /> if (</span><span style="color: #0000BB">$data</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">$inc </span><span style="color: #007700">= </span><span style="color: #0000BB">unserialize</span><span style="color: #007700">(</span><span style="color: #0000BB">$data</span><span style="color: #007700">);<br /> echo </span><span style="color: #DD0000">' -- filename: '</span><span style="color: #007700">, </span><span style="color: #0000BB">$inc</span><span style="color: #007700">[</span><span style="color: #DD0000">'request'</span><span style="color: #007700">][</span><span style="color: #DD0000">'SCRIPT_FILENAME'</span><span style="color: #007700">], </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /> echo </span><span style="color: #DD0000">' -- number of includes: '</span><span style="color: #007700">, </span><span style="color: #0000BB">count</span><span style="color: #007700">(</span><span style="color: #0000BB">$inc</span><span style="color: #007700">[</span><span style="color: #DD0000">'includes'</span><span style="color: #007700">]), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /> }<br /> echo </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /> }<br />} else {<br /> echo </span><span style="color: #DD0000">'I am totally clueless today.'</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span>
- </span>
- </code></div>
- </div>
- <div class="example-contents"><p>以上例程的输出类似于:</p></div>
- <div class="example-contents screen">
- <div class="cdata"><pre>
- PATH: /tmp/inclued
- Inclued file: inclued.56521.1
- -- filename: /Users/philip/test.php
- -- number of includes: 1
- Inclued file: inclued.56563.1
- -- filename: /tmp/none.php
- -- number of includes: 0
- Inclued file: inclued.56636.1
- -- filename: /tmp/three.php
- -- number of includes: 3
- </pre></div>
- </div>
- </div>
- </p>
- </div><hr /><div class="manualnavbar" style="text-align: center;">
- <div class="prev" style="text-align: left; float: left;"><a href="inclued.examples.html">范例</a></div>
- <div class="next" style="text-align: right; float: right;"><a href="ref.inclued.html">inclued 函数</a></div>
- <div class="up"><a href="inclued.examples.html">范例</a></div>
- <div class="home"><a href="index.html">PHP Manual</a></div>
- </div></body></html>