Welcome Guest, Not a member yet? Register   Sign In
I Keep getting HTTP 500. How do I effectively debug my app?
#1

[eluser]zechdc[/eluser]
--------------------------------- Solved! ---------------------------------
See Solution Below - Jump to Solution Below
--------------------------------- Solved! ---------------------------------


It seems like every time I forget a semi-colon, use a function that has not been properly loaded, etc... I get a HTTP 500.

I am used to php's debugging where it would tell me something like "Function getDomain() not defined on line 15" ...or whatever the error would usually say. Anyways, the code below completely broke my application because I used the function getDomain() but forgot to load the helper first. An HTTP 500 does not help at all when it comes time to find the error. Took me 40 minutes to figure it out Sad

I even set error logging to 4 in config but it was useless. Just told me a bunch of classes and helpers loaded fine.

How do I effectively debug my app with CI, so it gives me line numbers?

I am new to Codeigniter and have been using PHP for about three years. I am using a MAC with MAMP.

Code:
<?php
if($this->uri->segment(1))
{
    $this->load->helper('inflector');
    
    $title = humanize($this->uri->segment(1));
    if($this->uri->segment(2))
    {
        $title .= ' - ' . humanize($this->uri->segment(2));
    }

    $title .= ' - ' getDomain();
}else{
    $title = getDomain();
}
?>
#2

[eluser]zechdc[/eluser]
This is not the solution. My main question still applies. How do I find out where I have a syntax error when I forget a period or semi-colon? I still get a HTTP 500 if I forget a semi-colon or period.

In the code above, I forgot to put a dot in the following code
Code:
$title .= ' - ' . getDomain();

That was one cause of the HTTP 500 error.

Second cause:
I was using a template method I learned form nettuts CI video series. The code looks like this:

Code:
$data['content'] = 'login_view';
$this->load->view('templates/main', $data);
And the template looks like this
Code:
<?php $this->load->view('includes/header'); ?>
<?php $this->load->view($content); ?>
<?php $this->load->view('includes/footer'); ?>

Apparently that suppresses all php errors and warnings from showing up on screen. So I guess I will just go back to using
Code:
$this->load->view('templates/main');

UPDATE
Feb 14, 2011

Now that I have enabled display_errors in php.ini all errors are being displayed properly, even while using the above template method. My statement about the template suppressing all php errors is inaccurate. It seems to be working find now.
#3

[eluser]InsiteFX[/eluser]
My editor will tell me!

Maybe you need to get a good editor that will flag your errors and tell you.

InsiteFX
#4

[eluser]zechdc[/eluser]
Great idea!

Right now I am using TextMate which I love for its simplicity, but im thinking about switching to Coda.

What editor do you use?
#5

[eluser]InsiteFX[/eluser]
I use 2 different ones PHPDesigner by MPSoftware and Webulider.

InsiteFX
#6

[eluser]zechdc[/eluser]
--------------------------------- Solution! ---------------------------------

--------------------------------- Solution! ---------------------------------

--------------------------------- Solution! ---------------------------------

Quote:Update: Feb 25, 2011
Posted by John_Betong

It is not necessary to set display errors in the php.ini file they can be toggled using this code in your script

Code:
error_reporting(-1);
ini_set('display_errors', TRUE);

As mentioned in the User Guide it is best to switch errors off to prevent Joe Public from seeing your errors, etc

I had to turn on display_errors in php.ini
Code:
display_errors = On

php.ini location on a Mac running MAMP
Code:
/Applications/MAMP/conf/php5/

Now the code in my original post produces the following error.
Quote:Parse error: syntax error, unexpected T_STRING in /Applications/MAMP/htdocs/v3/application/views/includes/header.php on line 2

Advanced Debugging Tutorial

http://technosophos.com/content/debugging-your-php-code-xdebug-mamp-textmate-and-macgdbp-supportd

This article provides some wonderful information on how to setup xdebug with MAMP. After following the first couple instructions I was able to get more error reporting than I needed. Also, be sure to read the comments on that page. Huge help!

All you need is MAMP and xdebug to get it working. It also has some info for working with textmate... which is my preferred editor.
#7

[eluser]djeetee[/eluser]
@zechdc,

[quote author="zechdc" date="1297733857"]--------------------------------- Solution! ---------
http://technosophos.com/content/debugging-your-php-code-xdebug-mamp-textmate-and-macgdbp-supportd

This article provides some wonderful information on how to setup xdebug with MAMP. After following the first couple instructions I was able to get more error reporting than I needed. Also, be sure to read the comments on that page. Huge help!

All you need is MAMP and xdebug to get it working. It also has some info for working with textmate... which is my preferred editor.[/quote]

I actually went through that yesterday and got it all installed however I cannot seem to be able to debug (by setting a breakpoint) anywhere outside index.php. I have detailed the problem here:

i downloaded Xdebug and MacGDBp. installed them tried to debug a CodeIgniter 1.7 Controller. here is what happens:

-Xdebug and Macgdbp can talk.
-execution stops at the beginning of index.php
-i can step through index.php

the issue I have is that i cannot get the debugger to recognize and therefore stop at any breakpoint i set in any other php file. It only seems to debug index.php and the other php files it calls. Nothing i do in the breakpoint window seems to have any effect.

my config:

[xdebug]
zend_extension="/Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=1
One other note, my php.ini did not have any reference to the zend optimizer as some installation instructions say that i have to comment out. I'm using php 5.3.2.


I hope you could take a look at it and let me know if you can tell what the solution might be. essentially i would like to set up a breakpoint in one of the controllers and have XDebug/macgdbp stop when execution reaches that point.

thanks in advance.
#8

[eluser]zechdc[/eluser]
@djeetee

I was actually having this problem as well.

I wish I had a solid answer, but its more of a guess. I think it only stops on breakpoints that are actually outputting something. It makes sense to me since MacGDBp is waiting for a response from the server.

Take a look at the image I attached and I'll explain how I came about this a little more.

If you can't see the image I attached, here is a snippet of code that I added some breakpoints to. Line numbers with a star (*) in from of them are where I placed breakpoints.
Code:
5    echo form_open('contact/submit');
*6    echo form_input('name', 'Name', 'id="name"');
7    echo form_input('email', 'Email', 'id="email"');
8    
*9    $data = array(
10        'name'    =>    'message',
11        'cols'    =>    '39',
12        'rows'    =>    '15',
13        'value'    => set_value('message', 'Message'),
14        'id'    =>    'message',
15        );
*16    echo form_textarea($data);
17    echo form_submit('submit', 'Login', 'id="submit"');
18    ?>
19</div>
20
21[removed] //Javascript script tag removed
*22    $('#submit').click(function() {
23        var form_data = {
24            name: $('#name').val(),
25            email: $('#email').val(),
26            message: $('#message').val(),
27            ajax: 'zzzzzzzz1';
*28        };

Line 6 - It stopped at this breakpoint
Line 9 - It didn't stop, just jumped right on to line 16
Line 16 - It stopped
Line 22 - Didn't stop because its Javascript... and this is a PHP debugger, use firebug for Javascript
Line 28 - Didn't stop because its Javascript... and this is a PHP debugger, use firebug for Javascript

So as you can see, line 6 and 16 are the only places it actually stopped even though I set other breakpoints. The only thing line 6 and 16 have in common is that they both output while the other lines don't.

It seems like there has to be a better way, I just don't know of it. This way works pretty well for some stuff. As you can see from the image, when my script stopped on line 16, I can see what is in the $data array. So, it works... just have to remember to put breakpoint on script that outputs...

I hope this helps. Someone let me know if I'm wrong. I would love to know the real reason for this happening. If there is some way to fix this, let us know please Smile
#9

[eluser]djeetee[/eluser]
thanks for the quick reply!!! :-)

I had a feeling that it was something like that but the strange thing is that when i launch my website with the debugger enabled, it ALWAYS starts debugging on the first line of index.php. Probably because that's the default in the prefs. but after that you can debug the remaining code in index.php and all the other php file it calls. the call stack, variables, etc... all work.

Now once the code reaches a point where a view is displayed, bang the debugging session ends even though there are breakpoints all over the code which should be triggered as one clicks here and there.... but no BP triggers the debugger to swing back into action.

it's bizarre!

for now, i'm back to echo and log_message() the stone-age way of coding (is it really 2011??)

if you ever find out how we can get it to work please let me know.

thanks again.
#10

[eluser]zechdc[/eluser]
Ya, I have been looking for a decent way to debug PHP for the last 3 years. Guess I'm not looking hard enough because I still haven't found anything worth using Smile

Maybe we should just build a PHP debugger ;P

I'll be sure to update this post if I ever find something.




Theme © iAndrew 2016 - Forum software by © MyBB