Php debugger software?

Is there a PHP debugger? Which ones are popular?

+3
source share
3 answers

XDebug is considered the de facto standard. Its features include:

  • stack traces and function traces in error messages
  • memory allocation
  • protection for infinite recursions
  • profiling information for PHP scripts
  • code coverage analysis
  • debugging capabilities of your scripts interactively using the debug client

It can be installed through PECL:

pecl install xdebug

after which you should add this to your php.ini:

zend_extension="/usr/local/php/modules/xdebug.so"

You can also compile the source code. Full instructions here .

+8
+2

, . :
. , :

debugRelated/plantillaDebugable.htm

<style>
#Debug
{
    position:fixed;
    bottom: 0;
    right: 0;
    max-height: 80vh;
    overflow:auto;
    overflow-x: hidden;
    background: white;
    text-align: left;
    margin: auto;
    -webkit-box-shadow: 6px 7px 0px -3px rgba(0,0,0,0.68);
    -moz-box-shadow: 6px 7px 0px -3px rgba(0,0,0,0.68);
    box-shadow: 6px 7px 0px -3px rgba(0,0,0,0.68);
    border: 1px solid #aaa;
}

#Debug.Abierto
{
    width: 100%;
    left: 0;
}

#Debug h1.DebugableH1:hover
{
    background: #900;
    color: #eee;
}

#Debug h1.DebugableH1
{
    padding-right: 20px;
    background: #a22;
    cursor: pointer;
  -webkit-user-select: none;  /* Chrome all / Safari all */
  -moz-user-select: none;     /* Firefox all */
  -ms-user-select: none;      /* IE 10+ */
  user-select: none;
    margin: 0;
    height: 5vh;
    font-size: 15pt;
    text-align: right;
    text-decoration: underline;
}

#Debug div.DebugableDiv
{
    display: none;
    max-height: 100vh;
    overflow:auto;
    border: 2px solid black;
    padding: 15px;
    background: #aaa;
}

#Debug div.DebugableDiv hr
{
    margin: 30px;
    border-top: 3px solid #900;
}

#Debug div.DebugableDiv p
{
    font-size: 11pt;
    font-weight: 600;
    background: #fafafa;
    padding: 2px 5px;
    margin: 0 0 5px 0;
}
</style>
<script>
    function actividadDebug()
    {
        $('#Debug .DebugableDiv').hide();
        $('#Debug').removeClass('Abierto');
        $('#Debug').click(e=>{e.preventDefault(); return false;});
        $('#Debug h1').click((e)=>
        {
            e.preventDefault();
            $('#Debug .DebugableDiv').toggle();
            $('#Debug').toggleClass('Abierto');
            return false;
        });

        $(document).click(()=>
        {
            $('#Debug .DebugableDiv').hide();
            $('#Debug').removeClass('Abierto');
        });
    }
</script>
<div id='Debug'>
    <h1 class='DebugableH1'></h1>
    <div class='DebugableDiv'>{output}</div>
    <script>actividadDebug();</script>
</div>

debugRelated/enunciados.json

{
    "titulos":
    {
        "nombreTitulo": "Debug de '%s' - <strong>%s: </strong>",
        "nombre": "Debug de '%s': ",
        "titulo": "<strong>%s: </strong>"
    },
    "array":"<pre style=\"margin:5px;background:#f8f8f8; padding:10px 20px; border: 2px solid black\"><h3 style=\"font:600 12pt courier new; margin: 0\">%s</h3>%s</pre>",
    "simple":"<p>%s%s</p>"
}

debug.php

<!DOCTYPE html>
<html lang="es">  
    <head>    
        <title>{tituloPagina} - {sloganPagina}</title>    
        <meta charset="UTF-8">
        <meta name="title" content="{tituloPagina} - {sloganPagina}">
        <meta id='metaPagDescripcion' name="description" content="{descripcionPagina}">
      <meta name="keywords" content="{keywordsPagina}">
      <meta name="author" content="Alexis Leite - alexisleite@live.com">
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
        <script src="Jquery.js"></script>
    </head>  
    <body>
        <?php
class DebugBuffer
{
    private static $buffer = '';
    private static $plantilla;

    private static $inst;

    public function load()
    {
        Static::$plantilla = file_get_contents(__DIR__ . '/DebugRelated/plantillaDebugable.htm');
    }

    public static function escribir($que)
    {
        Static::$buffer .= $que;
    }

    public static function output()
    {
        return str_replace("{output}", Static::$buffer, Static::$plantilla);
    }
}
DebugBuffer::load();

class DebugStruct 
{
    private static $estructura;

    public static function get()
    {
        if(!Static::$estructura) Static::$estructura = json_decode(file_get_contents(__DIR__ . '/DebugRelated/enunciados.json'));
        return Static::$estructura;
    }
}

/**
 * Clase para escritor html.
 */
class Debugable
{
    // El nombre que se mostrara en el debug
    protected $debugName;
    // Se hace debug o no
    protected $debug = true;
    // El nivel al que se hace debug
    protected $debugLevel = 1;
    // Solo ese nivel o todos los niveles inferiores tambien
    protected $debugStrict = false;

    public function debug($level,$que,$titulo='')
    {

        if(!$this->debug
          || $this->debugStrict && $level != $this->debugLevel
          || !$this->debugStrict && $level > $this->debugLevel)
          return;

        $tit = '';
        if(isset($this->debugName) && $titulo != '')
            $tit .= sprintf(DebugStruct::get()->titulos->nombreTitulo,$this->debugName,$titulo);
        else if(isset($this->debugName))
            $tit .= sprintf(DebugStruct::get()->titulos->nombre,$this->debugName);
        else if($titulo != '')
            $tit .= sprintf(DebugStruct::get()->titulos->titulo,$titulo);
        if(is_array($que) || is_object($que))
        {
        $output = sprintf(DebugStruct::get()->array,$tit,print_r($que, true));
        }
        else
                $output = sprintf(DebugStruct::get()->simple,$tit,$que);

    DebugBuffer::escribir($output . PHP_EOL);
    }
}

class Test extends Debugable
{
    protected $debug = true;
    protected $debugName = 'Prueba';
    protected $debugLevel = 1;
    protected $debugStrict = false;

    public function __construct()
    {
        $arr = 
        [
            'a' => 
            [
                'aa' => 'aa',
                'ab' => 'ab'
            ],
            'b' =>
            [ 
                'ba' => 'ba',
                'bb' => [1,2,3,4,5,6,7]
            ]
        ];

      $this->debug(1,'Prueba','Titulo');
      $this->debug(1,$arr,'Array de prueba');
      echo DebugBuffer::output();
    }
}

new Test();
?>

    </body>
</html>

, , (protected $ debug), (protected $ debugName), , ($ debugLevel), ($ debugStrict).

$this->debug(1,'Prueba','Titulo');

1 - , . :

  • debug == false,
  • == true && debugStrict == true && level! = debugLevel,
  • == false && debugStrict == false && level> debugLevel,

:

    if(!$this->debug
              || $this->debugStrict && $level != $this->debugLevel
              || !$this->debugStrict && $level > $this->debugLevel)
              return;

, , , ,

DebugBuffer::output()

Any doubts please ask me. I will add a screenshot A
screenshot of my debugger working

You may notice that you need to put a file called jquery.js for it to work, you cannot change this link to the path of your jquery file

-1
source

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


All Articles