Skip to content

A demo on how Xdebug can make your life as a PHP developer even more awesome. 🤓

License

Notifications You must be signed in to change notification settings

jpcaparas/xdebug-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Xdebug Demo

xdebug-logo

A demo outlining the benefits of using Xdebug on your typical PHP development workflow.

Requirements

  1. PHP v5.6++ w/ Xdebug installed.
  2. An IDE that supports Xdebug. This demo uses PhpStorm.
  3. Google Chrome w/ the Xdebug helper extension installed.
  4. Shell access.

Installation

To get started with this project, run:

composer create-project \
--prefer-source \
--stability=dev \
jpcaparas/xdebug-demo \
[dir-name]

Once cloned, run tests to ensure everything is intact:

./vendor/bin/codecept run

Xdebug might already be installed on your machine; to find out, run:

php -v

... which should result in an output similar to this:

PHP 7.1.5 (cli) (built: May 13 2017 13:30:32) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Xdebug v2.5.1, Copyright (c) 2002-2017, by Derick Rethans

If you don't have the with Xdebug... line, you'll have to download, enable, and configure the Xdebug extension.

Atlassian has a good, multi-platform guide on how to install Xdebug.

Usage

Wiring everything up

Once you have Xdebug configured, mark breakpoints throughout your code base:

Mark breakpoints

Upon marking, ensure that your IDE has been set up to become a debug client.

Listen for incoming connections

... and allow the browser to connect to the client.

Chrome browser extension

Now spin up a built-in web server from the terminal and we'll start debugging:

php -S localhost:8000 -t public

Connecting to the debug client

Open your browser on http://localhost:8000. You should see a form that asks for a GitHub username.

Assuming that you have added breakpoints to the ./src/Services/GitHubService.php file, your should be able to breakpoint into the code upon sending the POST request.

If the connection was successful, you'll be taken to the Debugger pane on PhpStorm, where you'll see a lot of stuff going on:

At this point, all you need to do is familiarise yourself with the various commands at your disposal (e.g. frames, variables, console, stepping).

More information about the various Debugger features can be seen here.

Gotchas

composer has become slower following Xdebug's installation. Is it possible to disable Xdebug on composer usage?

Yes, append this nifty script on your ~/.bash_aliases file (or its equivalent):

alias composer="php -n -d memory_limit=-1 $(which composer)"

The -n flag effectively disables PHP from reading the php.ini file (where Xdebug is defined).

Resources

Coming soon...

Attributions

This demo is part of Pixel Fusion Engineering Talks held every Friday, wherein we showcase tools and methodologies that empower developer productivity.

About

A demo on how Xdebug can make your life as a PHP developer even more awesome. 🤓

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published