php[tek] 2017: Atlanta

Example that implements inclued into an application

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

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

// File to store the inclued information
$fp fopen('/tmp/wp.ser''w');
if (
$fp) {
$clue inclued_get_data();
    if (
$clue) {

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.

Exemplo #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

# Next, create the image
$ dot -Tpng -o inclued.png

Exemplo #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.

if (
$path && is_dir($path)) {

"Path: $path"PHP_EOL;

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

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

    foreach (
$inclues as $inclue) {

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

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

O exemplo acima irá imprimir algo similar à:

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

User Contributed Notes 3 notes

g dot kuizinas at anuary dot com
3 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,
admin at eexit dot net
6 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:

// Around line 254
else /* classes */
$filemap = array();

$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:
gtisza at gmail dot com
4 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:
To Top