Running Xdebug with Sublime Text from Command Line

Tags: July 11, 2015 6:15 PM
0 comments

Overview

Sometimes there is a case we spending more time on command line rather than on browser when developing a PHP application. It is true especially when we are in unit testing phase. Usually Xdebug remote debugging activated by sending XDEBUG_SESSION_START=session_key in query string or http post body. For debugging from command line we need to set environment variable XDEBUG_CONFIG="idkey=session_key".

Debugging with Sublime and Xdebug

Default Xdebug session name for Sublime Xdebug Client is "sublime.xdebug". Assuming all the configuration related with Xdebug and Sublime are done, here is the way to begin debugging from command line.

  1. Start Xdebug on Sublime by going to Tools » Xdebug » Start Debugging
  2. Set your break point somewhere in your code
  3. Run your PHP script on command line, here I'm using phpunit.
    $ XDEBUG_CONFIG="idkey=sublime.xdebug" phpunit app/tests/notifier/v1/UserLoginNotifierQueueTest.php
    
  4. Go back to Sublime and all the debugging window are presented, the execution still paused at the break point.
  5. We can start to examine variables or doing "Step-In/Out".

References

Share on Facebook Twitter