Chapter 2: Getting to Know and Love Xdebug

by Bruno Škvorc

  • stack traces - detailed output of the path the application took to reach a given error, including parameters passed to functions, in order to easily track the error down.
  • a prettier var_dump output which produces color coded information and structured views, similar to VarDumper, along with a a super-globals dumper
  • a profiler for finding out where the bottlenecks in your code are, and the ability to visualize those performance graphs in external tools. What this results in is a graph similar to that which Blackfire produces.
  • a remote debugger which can be used to remotely connect Xdebug with running code and an end-client like an IDE or a browser to step through breakpoints in code and execute line by line of your application.
  • code coverage which tells you how much of your code was executed during a request. This is almost exclusively meant to help with unit tests and finding out how much of your code is test-covered.

How do I use it?

With modern IDEs and Blackfire, is there even a need for Xdebug?

Let's Try It Out

<?php

echo $foo;

Turning Xdebug Off

;zend_extension=xdebug.so
xdebug.remote_enable = 1
xdebug.remote_connect_back = 1
xdebug.remote_port = 9000
xdebug.max_nesting_level = 512
sudo service php7.1-fpm restart

Location of ini File

File Clickthroughs

xdebug.file_link_format = phpstorm://open?%f:%l

Xdebug with Vagrant and PhpStorm

Using the Profiler

composer create-project --prefer-dist laravel/laravel xdebug
xdebug.profiler_enable_trigger = 1
xdebug.profiler_output_dir = /home/vagrant/Code/
 brew install qcachegrind --with-graphviz
Cachegrind explored

Forcing Xdebug's Render on Laravel

<?php

use IlluminateHttpRequest;

Route::get('/', function(Request $request){
    echo $foo;
    return view('welcome');
});
<?php
use IlluminateHttpRequest;

Route::get('/', function(Request $request){
    ini_set('display_errors', 1);
    restore_error_handler();
    echo $foo;
    return view('welcome');
});
Laravel's Xdebug call stack

Conclusion

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.212.27