Page 1 of 1

Turning on PHP Debugging and Error messages Necessary for us to properly help you! Rate Topic: -----

#1 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 796
  • Joined: 08-June 10

Posted 06 July 2010 - 01:23 PM

Debugging messages are a powerful tool; however, many production systems (and test systems for that matter) have them disabled by default. If your PHP script is crashing horribly and you are not getting any runtime error messages, it is likely that this is the case for you.
You can initiate PHP debugging messages for the server by changing the display_errors and error_level settings in php.ini. Unfortunately, this is not the best situation in a production system. Luckily, you can enable error reporting on a page by page basis by simply adding the following lines to the top of your PHP script:
<?php
 
error_reporting(E_ALL);
ini_set('display_errors', True);

...



For extra credit, you can create an include file (mine is aptly labeled debugging.php) that enables error reporting, and exposes my code to a couple of really handy functions:
<?php
$DEBUGGING = True;
$TRACECOUNT = 0;
 
if($DEBUGGING)
{
    error_reporting(E_ALL);
    ini_set('display_errors', True);
)
 
function trace($message)
 
    global $DEBUGGING;
    global $TRACECOUNT;
    if($DEBUGGING)
    {
        echo '<hr />'.$TRACECOUNT++.'<code>'.$message.'</code><hr />';
    }
}
 
function tarr($arr)
{
    global $DEBUGGING; 
    global $TRACECOUNT; 
    if($DEBUGGING) 
    { 
        echo '<hr />'.$TRACECOUNT++.'<code>'; 
        print_r($arr); 
        echo '</code><hr />'; 
    } 
} 
 
?>



I include this file at the top of every PHP page. The trace() and tarr() functions allow me to easily format my own debugging code, and $TRACECOUNT presents a nice interface for knowing where a script failed if it halts unexpectedly. By simply toggling the $DEBUGGING variable to false, my code is ready to be tested by QA. When the product is finalize, I remove the include call to debugging.php from my source files altogether.

This post has been edited by Motoma: 09 July 2010 - 05:04 AM


Is This A Good Question/Topic? 2
  • +

Replies To: Turning on PHP Debugging and Error messages

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3554
  • View blog
  • Posts: 10,332
  • Joined: 08-June 10

Posted 07 July 2010 - 11:41 AM

View PostMotoma, on 06 July 2010 - 08:23 PM, said:

function trace($message)
 
    global $DEBUGGING;
    global $TRACECOUNT;
    if($DEBUGGING)
    {
        echo '<hr />;'.$TRACECOUNT++.'<code>'.$msg.'</code><hr />';
    }
}


$message or $msg ?
Was This Post Helpful? 1
  • +
  • -

#3 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 796
  • Joined: 08-June 10

Posted 07 July 2010 - 12:15 PM

Good eye! A little hasty, I guess.
Was This Post Helpful? 0
  • +
  • -

#4 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 542
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Posted 08 July 2010 - 06:36 PM

You'll also notice that you're echoing out a semi-colon after the first horizontal rule in trace().
Was This Post Helpful? 0
  • +
  • -

#5 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 796
  • Joined: 08-June 10

Posted 09 July 2010 - 05:05 AM

Bah, this is what I get for whipping up code on the fly.

Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1