Difference between revisions of "Debugging"

From Freephile Wiki
Jump to navigation Jump to search
(temp save)
 
(tmp save)
Line 1: Line 1:
 
Debugging a PHP application can involve quite a bit of machinery, and effort getting that machinery setup.  But it's worth it because what alternative is there? <code>echo</code>?  Come on!
 
Debugging a PHP application can involve quite a bit of machinery, and effort getting that machinery setup.  But it's worth it because what alternative is there? <code>echo</code>?  Come on!
 +
 +
Thanks to Derrik Rethans, xdebug can do a ton of cool things for you.  For example, it overloads <code>[https://secure.php.net/var_dump var_dump()]</code> and gives '''you''' [http://www.xdebug.org/docs/display control over how you want deeply nested data structures to be displayed].
  
 
== First get Xdebug setup ==
 
== First get Xdebug setup ==
Line 5: Line 7:
  
 
=== Summary ===
 
=== Summary ===
'''Xdebug installed:''' 2.2.3
+
<blockquote>
'''Server API:''' Apache 2.0 Handler
+
'''Xdebug installed:''' 2.2.3 <br />
'''Windows:''' no
+
'''Server API:''' Apache 2.0 Handler <br />
'''Zend Server:''' no
+
'''Windows:''' no <br />
'''PHP Version:''' 5.5.9-1
+
'''Zend Server:''' no <br />
'''Zend API nr:''' 220121212
+
'''PHP Version:''' 5.5.9-1 <br />
'''PHP API nr:''' 20121212
+
'''Zend API nr:''' 220121212 <br />
'''Debug Build:''' no
+
'''PHP API nr:''' 20121212 <br />
'''Thread Safe Build:''' no
+
'''Debug Build:''' no <br />
'''Configuration File Path:''' /etc/php5/apache2
+
'''Thread Safe Build:''' no <br />
'''Configuration File:''' /etc/php5/apache2/php.ini
+
'''Configuration File Path:''' /etc/php5/apache2 <br />
'''Extensions directory:''' /usr/lib/php5/20121212+lfs
+
'''Configuration File:''' /etc/php5/apache2/php.ini <br />
 +
'''Extensions directory:''' /usr/lib/php5/20121212+lfs  
 +
</blockquote>
 +
Caveat: their script can't really tell where the xdebug configuration lives.  In Ubuntu, there is a /etc/php5/conf.d and configuration files in there add to the main php.ini.  So, you end up editing <code>sudo vim /etc/php5/conf.d/xdebug.ini </code>
  
Caveat: their script can't really tell where the xdebug configuration livesIn Ubuntu, there is a /etc/php5/conf.d and configuration files in there add to the main php.ini.  So, you end up editing <code>sudo vim /etc/php5/conf.d/xdebug.ini </code>
+
Once you see xdebug in your phpinfo() output, you know it's enabled -- which means that you can already get xdebug functionality out of your PHP scripts (e.g. var_dump() is overridden)But how do you get debugging working so that you can use it with your IDE?  That is covered in the '[http://www.xdebug.org/docs/remote remote]' section of the manual.
  
 
Following the sage advice of the [http://wiki.netbeans.org/HowToConfigureXDebug#General_Information Netbeans wiki], you want to get xdebug's '''debugclient''' working on localhost first, then add Netbeans.
 
Following the sage advice of the [http://wiki.netbeans.org/HowToConfigureXDebug#General_Information Netbeans wiki], you want to get xdebug's '''debugclient''' working on localhost first, then add Netbeans.
 +
 +
xdebug provides several configuration parameters as well as functions that you can use in your debugging code.  One important parameter is the <code>[http://www.xdebug.org/docs/stack_trace xdebug.file_link_format]</code> which determines the format of the links that are shown in stack traces.  This allows for integration with your IDE so that, for example, Netbeans will find and open the file in your local sources.
 +
 +
[http://www.xdebug.org/docs/profiler Profiling] your PHP code is another feature enabled by xdebug.

Revision as of 15:26, 9 October 2015

Debugging a PHP application can involve quite a bit of machinery, and effort getting that machinery setup. But it's worth it because what alternative is there? echo? Come on!

Thanks to Derrik Rethans, xdebug can do a ton of cool things for you. For example, it overloads var_dump() and gives you control over how you want deeply nested data structures to be displayed.

First get Xdebug setup[edit | edit source]

Xdebug is the project for debugging PHP. The wizard will show you how to upgrade your package version. In my case, the Xdebug packaged for Ubuntu was 2.2.3, but the more recent version is 2.3.3

Summary[edit | edit source]

Xdebug installed: 2.2.3
Server API: Apache 2.0 Handler
Windows: no
Zend Server: no
PHP Version: 5.5.9-1
Zend API nr: 220121212
PHP API nr: 20121212
Debug Build: no
Thread Safe Build: no
Configuration File Path: /etc/php5/apache2
Configuration File: /etc/php5/apache2/php.ini
Extensions directory: /usr/lib/php5/20121212+lfs

Caveat: their script can't really tell where the xdebug configuration lives. In Ubuntu, there is a /etc/php5/conf.d and configuration files in there add to the main php.ini. So, you end up editing sudo vim /etc/php5/conf.d/xdebug.ini

Once you see xdebug in your phpinfo() output, you know it's enabled -- which means that you can already get xdebug functionality out of your PHP scripts (e.g. var_dump() is overridden). But how do you get debugging working so that you can use it with your IDE? That is covered in the 'remote' section of the manual.

Following the sage advice of the Netbeans wiki, you want to get xdebug's debugclient working on localhost first, then add Netbeans.

xdebug provides several configuration parameters as well as functions that you can use in your debugging code. One important parameter is the xdebug.file_link_format which determines the format of the links that are shown in stack traces. This allows for integration with your IDE so that, for example, Netbeans will find and open the file in your local sources.

Profiling your PHP code is another feature enabled by xdebug.