Any way to trace the codes while it is run to help debug?

Discussion in 'PHP' started by aayybb, Jul 28, 2009.

  1. #1
    Hi,

    My program stuck sometimes and I would like to know how to trace each line of code without inserting tons of print or echo to help me debug.

    Thanks for any help in advanced.
     
    aayybb, Jul 28, 2009 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    What's you error reporting set at? You can put this at the top of the page to report all errors.

    error_reporting(E_ALL);

    Let me know if you were referring to something else.
     
    jestep, Jul 28, 2009 IP
  3. aayybb

    aayybb Peon

    Messages:
    128
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi,

    I have these in the beginning of my file.
    ini_set('display_errors', 1);
    error_reporting(E_ALL & ~E_NOTICE);

    My program works randomly. Sometimes it works and sometimes doesn't even though it is reading the same data (a zip file). All I did is testing the same code over and over. But sometimes it finished reading everything but sometimes it doesn't. It is like sometimes I got lucky and sometimes I didn't and no error message. I just want to know why same codes and same zip file but results differ randomly. I thought tracing it line by line might help to debug.
     
    aayybb, Jul 28, 2009 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    How long does the script take to process. I've seen scripts simply stop with no error when they timeout while uploading/processing a file.
     
    jestep, Jul 28, 2009 IP
  5. wrxbuzz

    wrxbuzz Peon

    Messages:
    41
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Keep in mind some hosts block the error_reporting() command and instead they echo it into a local text file, often called error_log.
     
    wrxbuzz, Jul 28, 2009 IP
  6. aayybb

    aayybb Peon

    Messages:
    128
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The max execution time is set to 30 (assume 30 seconds) in the php.ini. I know in the past I had gotten error message exceeding max execution time when it ran too long... But I have not gotten any error like that lately and the program just stopped in the middle. When it worked the time was actually longer than 30 seconds. It is a small zip file so it took around 1 minute. So this really confuses me.
     
    aayybb, Jul 28, 2009 IP
  7. aayybb

    aayybb Peon

    Messages:
    128
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hi,

    I did get some php or MYSQL error messages before so I think our hosting company is not blocking the error reporting.
     
    aayybb, Jul 28, 2009 IP
  8. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #8
    there's also a plugin for firebug (under mozilla / firefox) called firePHP - it allows you to output variables, objects and functions to the firebug console through x-headers :) its pretty slick and VERY useful for debugging - needs php 5+ though.
     
    dimitar christoff, Jul 28, 2009 IP
  9. aayybb

    aayybb Peon

    Messages:
    128
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Thanks a lot. I will try that later. So far, I changed the sequence of my codes and seems to be fine. Hope it stays that way.
     
    aayybb, Jul 29, 2009 IP