茫茫網海中的冷日 - 對這文章發表回應
茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1729348 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
CHIMEI_TL32V7500D_00032.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

對這文章發表回應

發表限制: 非會員 可以發表

發表者: 冷日 發表時間: 2014/5/21 8:11:08

Turning on PHP Debugging and Error Messages


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);

The way I like to handle debugging in my systems, is create an include file (aptly labeled lib.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 lib.debugging.php from my source files altogether.


I hope someone finds this useful,


Motoma



原文出處:
Turning on PHP Debugging and Error Messages
還有這篇可以參考:debugging - How to get useful error messages in PHP? - Stack Overflow
內容圖示
url email imgsrc image code quote
樣本
bold italic underline linethrough   












 [詳情...]
validation picture

注意事項:
預覽不需輸入認證碼,僅真正發送文章時才會檢查驗證碼。
認證碼有效期10分鐘,若輸入資料超過10分鐘,請您備份內容後,重新整理本頁並貼回您的內容,再輸入驗證碼送出。

選項

Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|