谷歌镜像 伍佰目录 短网址
  当前位置:海洋目录网 » 站长资讯 » 站长资讯 » 文章详细 订阅RssFeed

PHP - Manual: Example that implements inclued into an application

来源:网络转载 浏览:40474次 时间:2024-02-04
inclued 函数 » « 范例
  • PHP 手册
  • 函数参考
  • 影响 PHP 行为的扩展
  • inclued
  • 范例

Example that implements inclued into an application

This example demonstrates the process of implementing inclued into an existing application, and viewing the results.

Example #1 Getting the data within the PHP application itself (function)

<?php
// File to store the inclued information
$fp = fopen('/tmp/wp.ser', 'w');
if ($fp) {
    $clue = inclued_get_data();
    if ($clue) {
        fwrite($fp, serialize($clue));
    }
    fclose($fp);
}
?>

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 gengraph.php that creates a dot file that requires the » graphviz library. However, this form is not required.

Example #2 Example use of gengraph.php

This example creates an image named inclued.png that shows the inclued data.

# 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

Example #3 Listing data via inclued dumps (configuration)

When using the inclued.dumpdir directive, files (include clues) are dumped with every request. Here's one way to list those files, and unserialize() them.

<?php
$path = ini_get('inclued.dumpdir');
if ($path && is_dir($path)) {

    echo "Path: $path", PHP_EOL;

    $inclues = new GlobIterator($path . DIRECTORY_SEPARATOR . 'inclued*');

    if ($inclues->count() === 0) {
        echo 'No clues today', PHP_EOL;
        exit;
    }

    foreach ($inclues as $inclue) {

        echo 'Inclued file: ', $inclue->getFilename(), PHP_EOL;

        $data = file_get_contents($inclue->getPathname());
        if ($data) {
            $inc = unserialize($data);
            echo ' -- filename: ', $inc['request']['SCRIPT_FILENAME'], PHP_EOL;
            echo ' -- number of includes: ', count($inc['includes']), PHP_EOL;
        }
        echo PHP_EOL;
    }
} else {
    echo 'I am totally clueless today.', PHP_EOL;
}
?>

以上例程的输出类似于:

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
add a note

User Contributed Notes 3 notes

up down 2 g dot kuizinas at anuary dot com6 years ago If you install the module and execute it via CLI it will not produce any errors when not enabled. It took me quite a bit of time until I realised that by default the module is disabled, http://www.php.net/manual/en/inclued.configuration.php. up down 1 admin at eexit dot net8 years ago The new gengraph.php has « -t » parameter set to « includes » by default. Don't forget to specify it to « classes » for most of all projects.

Since PHP 5.3, namespace operators are stripped by Graphiz when the graph is generated. Add the following tips to escape namespace operators:

<?php
// Around line 254
else /* classes */
{
    $filemap = array();

    foreach($data["classes"] as $k => $v) {
        $class = $v;

    // Here is the tip to remove namespaces
        $class['name'] = str_replace('\\', '\\\\', $class['name']);
        $class['mangled_name'] = str_replace('\\', '\\\\', $class['mangled_name']);

// ...
?>

By the way, if you are looking for an easy way to use inclued, take a look at my library: http://www.eexit.net/projects/inclued.html
up down 0 gtisza at gmail dot com6 years ago Note that inclued does not work correctly when xdebug is enabled (the includes array remains empty; consequently, graphing the classes works but graphing the files does not). Bug report: https://bugs.php.net/bug.php?id=59419 add a note

官方地址:https://www.php.net/manual/en/inclued.examples-implementation.php

  推荐站点

  • At-lib分类目录At-lib分类目录

    At-lib网站分类目录汇集全国所有高质量网站,是中国权威的中文网站分类目录,给站长提供免费网址目录提交收录和推荐最新最全的优秀网站大全是名站导航之家

    www.at-lib.cn
  • 中国链接目录中国链接目录

    中国链接目录简称链接目录,是收录优秀网站和淘宝网店的网站分类目录,为您提供优质的网址导航服务,也是网店进行收录推广,站长免费推广网站、加快百度收录、增加友情链接和网站外链的平台。

    www.cnlink.org
  • 35目录网35目录网

    35目录免费收录各类优秀网站,全力打造互动式网站目录,提供网站分类目录检索,关键字搜索功能。欢迎您向35目录推荐、提交优秀网站。

    www.35mulu.com
  • 就要爱网站目录就要爱网站目录

    就要爱网站目录,按主题和类别列出网站。所有提交的网站都经过人工审查,确保质量和无垃圾邮件的结果。

    www.912219.com
  • 伍佰目录伍佰目录

    伍佰网站目录免费收录各类优秀网站,全力打造互动式网站目录,提供网站分类目录检索,关键字搜索功能。欢迎您向伍佰目录推荐、提交优秀网站。

    www.wbwb.net