jpcaparas / xdebug-demo
A demo outlining the benefits of using Xdebug on your typical PHP development workflow.
Installs: 8
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Type:project
Requires
- php: >=5.6 || >= 7.0
- guzzlehttp/guzzle: ^6.2
- slim/slim: ^3.8
- slim/twig-view: ^2.2
Requires (Dev)
- codeception/codeception: ^2.3
This package is not auto-updated.
Last update: 2024-11-10 04:27:43 UTC
README
A demo outlining the benefits of using Xdebug on your typical PHP development workflow.
Requirements
- PHP v5.6++ w/ Xdebug installed.
- An IDE that supports Xdebug. This demo uses PhpStorm.
- Google Chrome w/ the Xdebug helper extension installed.
- 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:
Upon marking, ensure that your IDE has been set up to become a debug client.
... and allow the browser to connect to the client.
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 oncomposer
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.