PHP
  Home arrow PHP arrow Page 2 - The X-debug Extension
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

The X-debug Extension
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2009-02-02


    Table of Contents:
  • The X-debug Extension
  • Getting started using the X-debug library
  • Keeping track of file calls with the X-debug extension
  • Working with the xdebug_call_line() function

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    The X-debug Extension - Getting started using the X-debug library
    ( Page 2 of 4 )

    Naturally, before you start using the X-debug library, it’s necessary to install it on your own testing web server. To do so, you should navigate to its official web site, located at http://x-debug.org, and then proceed to download either the Windows or Linux module. For Windows, it’s provided as a .DLL file.

    In this case, I’ll be using the library that works with PHP 5.2.1 – 5.2.6 for Windows. Once you’ve downloaded the correct file, place it in any directory of your choice (mine is “ext” under the PHP folder) and finally add the following line to your php.ini file within the “dynamic modules” section:


    zend_extension_ts="c:/php/ext/php_xdebug-4.4.1-2.0.2.dll"


    Please make sure that the above line includes the full path to the X-debug extension, so it can be found by the PHP engine.

    Assuming that the X-debug PHP extension has been installed correctly on the web server, it’s time to test it and see if it’s really working as expected. To do this, I’m going to build a basic sample class, called “FileReader,” that looks like this:


    class FileReader{

    private $path;

    public function __construct($path){

    $this->path=$path;

    }

    public function read(){

    if(!$content=file_get_contents($this->path)){

    throw new Exception('Error reading target file.');

    }

    return $contents;

    }

    }


    As shown above, the previous “FileReader” class is useful for fetching the contents of a selected file, which can be directly echoed to the browser via its “read()” method. So far, there is nothing interesting happening here, right? 

    This is about to change. Now I’m going to create a simple script that uses this class and passes into it an invalid path for the file to be read. Here it is:


    try{

    $fileReader=new fileReader('invalid_path/data.txt');

    echo 'Contents of target file are the following .'.$fileReader->read();

    }

    catch(Exception $e){

    echo $e->getMessage();

    exit();

    }


    If all goes well (or wrong, to be more precise), as soon as the previous script is executed, the X-debug library will swing into action, and display the following error message:



    At this point, you’ll have to agree with me that things are getting pretty exciting now. As shown before, the X-debug extension provides plenty of information about the error raised by the previous script, informing you not only about the nature of the error itself, but also about a few other useful debugging parameters, including the stack of calls that has been made during the script’s execution, the time it took to process each of these calls and the memory used, and finally the function and the location of each stack entry.

    So at this point, you can see that the X-debug extension is up and running in the web server, and naturally it can be used for debugging PHP applications by means of additional data that isn’t available by default with the PHP interpreter.

    So far, so good. At this stage I've demonstrated, through an introductory hands-on example, how to perform a basic test of the capabilities offered by the X-debug extension for debugging PHP applications in a detailed way.

    However, this is only the beginning of this hopefully educational journey. The X-debug library comes equipped with many other handy features that deserve a close analysis. Thus, it’s time to continue exploring them in depth.

    In the section to come, I’ll be showing you how to use the library’s “xdebug_call_file()” function to keep track of the location of the files included and executed by a PHP application. So, please click on the link that appears below and keep reading.



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Adding Ordering and Grouping Clauses to the ...
    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek