Welcome Guest, Not a member yet? Register   Sign In
Using XDebug with CodeIgniter
#1

[eluser]Josamoto[/eluser]
Hi all, it's me Mr.Absurd Questions again. Smile

I am using the Europa Eclipse IDE with PDT version which comes with XDebug. It's a nifty debugger to use for PHP with step by step debugging, breakpoints and the works. Very handy to have. I can't live without it.

The debugger however starts your application with a URL that looks similar to the following:
http://www.fingfong.net/doit?XDEBUG_SESS...8163298751

CI tells me I have illegal characters in my URL, and when I add the ?=& to the config.php file ($config['permitted_uri_chars'] = 'a-z 0-9~%.:_-';), some regex is failing and spitting out an error.

How can I get CI to ignore the section?
#2

[eluser]Neovive[/eluser]
Here are some notes summarizing the process I utilized to get the Zend Debugger working with Eclipse PDT on WAMP server. It's pieced together from various sites and some postings in the CI forum. I haven't tried it in a few months. If it works, I will add it to the Wiki.

The Zend Debugger is available for free and seems to integrate better with Eclipse PDT than XDebug. the process eventually worked, but it was hard to get much value out of the debugger, since CI routes everything through the front controller.


Installing Eclipse PDT v1 with Zend Debugger on WAMP Server for Code Igniter

1) Download and install WAMP Server from http://www.wampserver.com/en/

2) Download the Debugger Extension from Zend Downloads (http://downloads.zend.com/pdt/server-debugger/) You need to download the Debugger Extension packet for the appropriate operating system. Unpack the zipped packet and take the dll (or so) file which matches the PHP version you have currently running. E.g. for PHP 5.2.0 the correct file is ZendDebugger.dll inside 5_2_x_comp directory.

3) Unzip the proper ZendDebugger.dll and copy to C:\wamp\php\ext

4) Add the following lines to your php.ini file:
zend_extension_ts=c:/wamp/php/ext/ZendDebugger.dll
zend_debugger.allow_hosts=127.0.0.1,list.your.ip.addresses [add comma separated list of all applicable ip's for development server]
zend_debugger.expose_remotely=always

5) Restart server and create a <?=phpinfo();?> script. You should see a "With Zend Debugger ....." under the Powered By Zend logo.

6) In CI update the application/config.php as follows:
$config['enable_query_strings'] = TRUE;
$config['permitted_uri_chars'] = '';


7) In CI update the system/libraries/Router.php (as per http://ellislab.com/forums/viewthread/59944/)
line 288
Code:
function _get_uri_string()
    {
        if (strtoupper($this->config->item('uri_protocol')) == 'AUTO')
        {
            // If the URL has a question mark then it's simplest to just
            // build the URI string from the zero index of the $_GET array.
            // This avoids having to deal with $_SERVER variables, which
            // can be unreliable in some environments
            if (is_array($_GET) AND count($_GET) == 1)
            {
                // Note: Due to a bug in current() that affects some versions
                // of PHP we can not pass function call directly into it
                $keys = array_keys($_GET);
                print_r($keys); die();
              
                if (in_array('debug_session_id', $keys)) {    // debug flag used by Zend Debugger
                    return '';
                } else {
                    return current($keys);
                }              
            }
      
            // Is there a PATH_INFO variable?
            // Note: some servers seem to have trouble with getenv() so we'll test it two ways      
            $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO');  
            if ($path != '' AND $path != "/".SELF)
            {
                return $path;
            }
                  
            // No PATH_INFO?... What about QUERY_STRING?
            $path =  (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING');  
            if ($path != '')
            {
                return $path;
            }
          
            // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists?
            $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO');  
            if ($path != '' AND $path != "/".SELF)
            {
                return $path;
            }

            // We've exhausted all our options...
            return '';
        }
        else
        {
            $uri = strtoupper($this->config->item('uri_protocol'));
          
            if ($uri == 'REQUEST_URI')
            {
                return $this->_parse_request_uri();
            }
          
            return (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri);
        }
    }

8) Right-click on index.php file in Eclipse and choose "Debug as PHP Webpage"

9) Configure Debug Properties: (click on debug button and and select "Debug Dialog")
Make sure "Zend" is set as the server debugger
Set the URL to your homepage: (e.g. http://localhost/index.php)
Advanced: "Debug All Pages"
Leave "Break at first line"

10) Run through the debug once (it will give a 404 Not Found the first time), then open Firefox and launch your URL. This will automatically trigger the debugger in Eclipse and it should work from the browser. Use "Step Into" to watch CI work it's magic.


References:
1) PDT Wiki: Installing the Zend Debugger
http://www.thierryb.net/pdtwiki/index.ph...d_Debugger

2) CI: http://ellislab.com/forums/viewthread/59359/
http://ellislab.com/forums/viewthread/59944/

3) PDT Wiki: Source level debugging and Zend Firefox Extension
http://www.thierryb.net/pdtwiki/index.ph..._Debugging
#3

[eluser]ginger_tosser[/eluser]
Neovive,

I'm completely new not only to CI but also PHP & server side stuff (I'm usually a plain vanilla client side HTML & JS, and not very good at either :down: )
I've installed xampp and eclipse/pdt rather than wamp but when I try to debug even a simple PHP script(non-CI) the code doesn't break (I've tried both Zend and XDebug). Is there anything special about wamp, as opposed to xampp, that helps this along? or am I just a useless noob that doesn't understand even half of what I've done, just followed instructions blindly?
#4

[eluser]Neovive[/eluser]
mdale,

Welcome to CI. Debugging in PHP is always a weird thing -- I have never found it very useful and haven't used it since switching to CI -- it's very hard to follow the code, since CI (and all other PHP frameworks) go back and forth between core framework classes and your custom code. You have to set your breakpoints very carefully.

Regarding your questions, XAMPP and WAMP are essentially the same thing -- so I doubt that is the issue. I have never used XAMPP though. You can download WAMP at (http://www.wampserver.com/).

Here are a few other things to try:

1) Make sure the Debugger DLL's are installed properly by checking phpinfo().
2) Make sure to set a breakpoint in Eclipse prior to starting the debugger.
3) Make sure to use the "Step Into" button to run the code, so you can watch what happens.


Overall, I would recommend using the the built-in CodeIgniter Profiler, which outputs most of the information needed to successfully debug. Adding a few random print_r statements seems to handle the rest. To use the CI Profiler, just add $this->output->enable_profiler(TRUE); to your controller. If you want to include Session information in the profiler output (which I find very useful), do the following:

1) Create a file "My Profiler.php" in the "application/libraries" folder.
2) Insert the following code:

Code:
<?
class MY_Profiler extends CI_Profiler {

    function MY_Profiler()     {
        
        $CI =& get_instance();
        parent::CI_Profiler();
    }

    // --------------------------------------------------------------------

    /**
     * Compile $_POST Data
     *
     * @access    private
     * @return    string
     */    
    function _compile_session() {    
        $output  = "\n\n";
        $output .= '<fieldset style="border:1px solid #020;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
        $output .= "\n";
        $output .= '<legend style="color:#020;">SESSION DATA</legend>';
        $output .= "\n";
        
        if (count($this->CI->session->userdata) == 0) {
            $output .= "<div style='color:#009900;font-weight:normal;padding:4px 0 4px 0'>No Session data exists</div>";
        } else {
            $output .= "\n\n<table cellpadding='4' cellspacing='5' border='0' width='100%'>\n";
            
            foreach ($this->CI->session->userdata as $key => $val)  {
                                
                $output .= "<tr><td align='right' width='20%' style='color:#000;background-color:#ddd;padding:4px 10px;'>$key</td><td align='left' width='80%' style='color:#000;font-weight:normal;background-color:#ddd;padding:4px 10px;'>";
                if (is_array($val)) {
                        $output .= "<pre>" . htmlspecialchars(stripslashes(print_r($val, true))) . "</pre>";
                } else     {
                    $output .= htmlspecialchars(stripslashes($val));
                }
                
                $output .= "</td></tr>\n";
            }
        }
                    
        $output .= "</table>\n";        
    
        $output .= "</fieldset>";

        return $output;    
    }
    
    // --------------------------------------------------------------------
    
    /**
     * Run the Profiler
     *
     * @access    private
     * @return    string
     */    
    function run($output = '')
    {        
        $output = '<br clear="all" />';
        $output .= "<div style='background-color:#fff;padding:10px;'>";
        $output .= $this->_compile_benchmarks();
        $output .= $this->_compile_post();
        $output .= $this->_compile_session();
        $output .= $this->_compile_queries();
        
        $output .= '</div>';
        
        return $output;
    }    

}
?&gt;
#5

[eluser]Unknown[/eluser]
I found this guy, his blog.
He created Firefox extension for creating xdebug sessions without url modification. It is very helpfull!!




Theme © iAndrew 2016 - Forum software by © MyBB