-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathbacktrace.php
59 lines (51 loc) · 1.41 KB
/
backtrace.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
function test1() {
test2();
}
function test2() {
while(true) {
co::sleep(10);
echo __FUNCTION__." \n";
}
}
$cid = go(function () {
test1();
});
go(function () use ($cid) {
while(true) {
echo "BackTrace[$cid]:\n-----------------------------------------------\n";
echo get_debug_print_backtrace(co::getBackTrace($cid))."\n";
co::sleep(3);
}
});
function get_debug_print_backtrace($traces){
$ret = array();
foreach($traces as $i => $call){
$object = '';
if (isset($call['class'])) {
$object = $call['class'].$call['type'];
if (is_array($call['args'])) {
foreach ($call['args'] as &$arg) {
get_arg($arg);
}
}
}
$ret[] = '#'.str_pad($i - $traces_to_ignore, 3, ' ')
.$object.$call['function'].'('.implode(', ', $call['args'])
.') called at ['.$call['file'].':'.$call['line'].']';
}
return implode("\n",$ret);
}
function get_arg(&$arg) {
if (is_object($arg)) {
$arr = (array)$arg;
$args = array();
foreach($arr as $key => $value) {
if (strpos($key, chr(0)) !== false) {
$key = ''; // Private variable found
}
$args[] = '['.$key.'] => '.get_arg($value);
}
$arg = get_class($arg) . ' Object ('.implode(',', $args).')';
}
}