Is it possible to determine which PHP file generated some output

Sometimes I have problems in which a PHP file, somewhere on a large system, generates false output in certain situations.

This may be due to the fact that someone accidentally typed a space or other character in front of the opening tag <?phpor left unwanted debugging echoin place or included some spaces after the last closing tag ?>.

Is there a way to generate a log that shows all the PHP files that generated some output, along with their output?

If not, is there any other way that can be suggested to track this issue?

Edit: clarify - the system I'm running on is Moodle (not directly related to the case, but as it was asked ...), and in this case the output was during the database update (but I had a similar problem with random characters are displayed at another time). There are a very large number of different PHP scripts loaded into memory to create the page, so manually determining what generates the unwanted output was not a very attractive prospect ...

+4
source share
2 answers

if your "only" problem is text outside php tags token_get_all () can help you. All (?) External php tags are reported as T_INLINE_HTML (312), so they are easy to filter.
For instance.

<?php
for($t=0;$t<10; $t++) { ?>

<?php
}
?>

<?php
$at = token_get_all( file_get_contents(__FILE__) );
foreach($at as $t) {
    if ( is_array($t) && T_INLINE_HTML===$t[0]) {
        echo 'inline html @ line ', $t[2], "\r\n";
    }
}

( )

inline html @ line 3
inline html @ line 7

- get_included_files() RecursiveDirectoryIterator, .

+1

, , . , .

1) Apachetop

-, , , .

2) lsof

watch -n1 "lsof | grep '\.php'"

.php . , ,

3) xdebug xdebug.

; xdebug . , , , . / . , , .

,

0

Source: https://habr.com/ru/post/1533925/


All Articles