LinkedNestBlog

PHP Debug : Basically Functions Of Xdebug

by 이진원Dev
PHP Debug : Basically Functions Of Xdebug

Ref.] 
https://opentutorials.org/course/692/3756

  • Xdebug's basically functions
    • Context 
      • source code
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        <?php
            function fix_string($a){
                echo "Called @ ".
                xdebug_call_file().
                " : ".
                xdebug_call_line().
                " from ".
                xdebug_call_function();
            }
         
            $ret = fix_string(array('Shrek'));
        ?>
        cs
      • See Result
    • Memory
      • source code
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        <?php
        $text = "hello world";
        $prev_mem = xdebug_memory_usage();
        echo '<h1>메모리 체크</h1>';
        for( $i = 0 ; $i < 10 ; $i++ ){
            $text.=$text;
            echo 'seq : '.$i.' : xdebug_memory_usage = '.xdebug_memory_usage().' : xdebug_memory_usage-prev_memory = '.(xdebug_memory_usage()-$prev_mem).' : text : '.strlen($text)."\n";
            echo '<br/>';
        }
        ?>
        cs
      • See Result
    • Excution Time
      • source code
        1
        2
        3
        4
        5
        6
        7
        8
        <?php 
        echo '<h1>실행시간</h1>';
         
        for( $i = 0 ; $i < 3 ; $i++ ){
            echo xdebug_time_index().'<br/>';
            sleep(1);
        }
        ?>
        cs
      • view result
    • Data Output
      • source code
        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
        <?php
        class test {
            public $publ = false;
            private $priv = true;
            protected $prot = 42;
        }
         
        $t = new test;
        $t -> publ = $t;
         
        $data = array(
            '1' => 'just one',
            '2' => array(
                    '2.1' => array(
                        '2.1.0' => 210,
                        '2.1.1' => array(
                            '2.1.1.0' => 3.1415,
                            '2.1.1.1' => 2.7,    
                        )
                    )
                ),
            '3' => $t,
            '4' => range(0, 5),
            );
        var_dump($data);
        ?>
        cs
      • view result through web browser
    • View Global Parameters
      • source code
PHP Debug : Basically Functions Of Xdebug · LinkedNest Blog