Naturally profile multiple scripts in PHP7

Since the release of PHP 7, it is now impossible to profile the entire selection of scripts using declare(ticks=1)in your base file, and then using to register_tick_function()track each tick, since it should no longer include paths. According to the PHP bug registered at https://bugs.php.net/bug.php?id=71448 , this will never be available again in PHP 7.

Due to an implementation error, the declare directive (ticks = 1) leaked into different compilation units until PHP 7.0. This is not how declare () directives should work, which are per-file or per-scope.

Are there any alternatives to this approach using native PHP (not C or pear extensions, etc.) that are available to me in PHP 7, which will allow me to profile each function or file that is called when the page loads, getting the details of the actual file path.

My initial question, which led to the detection of the error, can be found in How to avoid reusing ticks in every file in PHP 7 , this question now concerns alternative methods.

+6
source share
1 answer

declare(ticks=1) . /, , .., , , , , .

PHP Xdebug. :

, , PHP, , (, /).

PHP Userland ( tick)

, declare(ticks=1); ( # 71448), " " ( , ), .

, , , - proxy. PoC (Gist on Github) , , . test.php , , other.php declare(ticks=1); , include, :

...
tick_handler() called
#0  tick_handler(1) called at [/home/hakre/stream-wrapper-default-files/test.php:18]
#1  tick_handler() called at [/home/hakre/stream-wrapper-default-files/other.php:2]
#2  include(/home/hakre/stream-wrapper-default-files/other.php) called at [/home/hakre/stream-wrapper-default-files/test.php:24]
...

tick (: test.php):

<?php
/**
 * Inject declare ticks on include
 */
declare(ticks=1);

require __DIR__ . '/streamwrapper.php';

FileStreamWrapper::init();

// using a function as the callback
register_tick_function('tick_handler', true);


// Function which is called on each tick-event
function tick_handler()
{
    echo "tick_handler() called\n";
    debug_print_backtrace();
}

register_tick_function('tick_handler');

include "other.php";
include "another.php"; # file does not exists

gist , include, PHP / . .., .., (), , . / - , ( , ...). PoC , .

() , PoC .

+2

All Articles