생활코딩

Coding Everybody

코스 전체목록

닫기

Xdebug 기본 기능

Context

현재 실행되고 있는 함수나 메소드의 맥락을 제공한다. 

1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
function fix_string($a)
{
echo "Called @ ".
xdebug_call_file().
":".
xdebug_call_line().
" from ".
xdebug_call_function();
}
$ret = fix_string(array('Derick'));
?>

Memory

1
2
3
4
5
6
7
8
<?php
$text = "coding everybody";
$prev_mem = xdebug_memory_usage();
for($i=0; $i<10; $i++){
$text.=$text;
echo $i.':'.xdebug_memory_usage().':'.(xdebug_memory_usage()-$prev_mem).':'.strlen($text)."\n";
}
?>

실행시간

1
2
3
4
5
6
7
<?php
echo xdebug_time_index()."\n";
for($i=0; $i<3; $i++){
echo xdebug_time_index()."<br />\n";
sleep(1);
}
?>

데이터 출력

xdebug는 var_dump의 출력 방식을 웹과 CLI에 맞게 변경한다.  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
class test {
public $pub = false;
private $priv = true;
protected $prot = 42;
}
$t = new test;
$t->pub = $t;
$data = array(
'one' => 'a somewhat long string!',
'two' => array(
'two.one' => array(
'two.one.zero' => 210,
'two.one.one' => array(
'two.one.one.zero' => 3.141592564,
'two.one.one.one' => 2.7,
),
),
),
'three' => $t,
'four' => range(0, 5),
);
var_dump( $data );
?>

웹에서 실행한 결과 

CLI로 실행한 결과 (xdebug.cli_color의 설정값을 2로 했을 때)

전역변수 열람

1
2
3
4
5
<?php
ini_set('xdebug.dump.GET', '*');
ini_set('xdebug.dump.SERVER','*');
xdebug_dump_superglobals();
?>

댓글

댓글 본문
  1. Minki Choi
    var_dump 출력이 보기좋게 변환이 안될때는 php.ini 파일에서 html_errors 설정값을 Off -> On 으로 변경하고 아파치 재시작하면 잘보이네요 :]
  2. 쌈닭
    :D
버전 관리
egoing
현재 버전
선택 버전
공동공부
graphittie 자세히 보기