PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<dotnet_loaddebug_backtrace>
view the version of this page
Last updated: Sun, 02 May 2004

XXVI. Funzioni di gestione degli errori e di logging

Le seguenti sono le funzioni per la gestione degli errori ed il logging. Esse permettono di definire regole personalizzate per la gestione degli errori, e anche di modificarne la modalità della gestione stessa. Ciò permette di cambiare ed integrare i messaggi di errore adattandoli alle vostre esigenze.

Grazie alle funzioni di logging, è possibile inviare messaggi direttamente ad altre macchine, alla posta elettronica (o ad un gateway pager o di posta elettronica!), ai log di sistema, ecc., in modo da effettuare il log e controllare selettivamente le parti più importanti delle vostre applicazioni e siti web.

Le funzioni di restituzione dell'errore consentono la personalizzazione del livello e del tipo di errore, dal semplice avviso sino a funzioni personalizzate restituite durante gli errori.

Sommario
debug_backtrace --  Generates a backtrace
debug_print_backtrace --  Prints a backtrace
error_log -- invia un messaggio di errore
error_reporting -- definisce quali errori di PHP vengono restituiti
restore_error_handler --  Ripristina la precedente funzione di gestione dell'errore
set_error_handler --  Configura una funzione di gestione dell'errore definita dall'utente.
trigger_error --  Genera un messaggio a livello utente di errore/avviso/avvertimento message
user_error --  Genera un messaggio di errore/avviso/avvertimento a livello utente


add a note add a note User Contributed Notes
Funzioni di gestione degli errori e di logging
rusty at socrates dot berkeley dot edu
20-May-2004 11:50
When you set error_log in the php.ini file: on unix (solaris with apache at least) the file you specify must be writable by whoever your web server runs as.  For example, on my system apache runs as the user nobody so I must make sure that the file I specified for error_log is owned by nobody, or world writable.
Martin F.
21-Aug-2003 03:22
Another way of handling errors:

ob_start();
foo(); // must not output anything to the output buffer
$errorstring = ob_get_contents();
ob_end_clean();
if(strlen($errorstring)) bar($errorstring); // your error-handling function
Warhog
11-Jul-2003 04:06
For debugging it's sometimes nice if PHP directly shows the source of the line which caused the error!

function my_error($nr, $text, $file, $line)
{ if (is_readable($file))
  { $source = file($file);
   $source = htmlspecialchars($source[$line-1]); }
  else
  { $source = "<i>n/a</i>"; }
  die("error $nr in $file at $line: <div><code>$source</code></div>"); }

error_reporting(0);
set_error_handler("my_error");
webmaster at zdarmanet dot net
26-Jan-2003 04:48
I use something like this (and of course all necessary stuff like set_error_handler):

function myHandler(...) {
  include(...) // the code loaded in case of error
}

Then one of my scripts stops execution after the second pass throw a line like:

  list(...)=mysql_fetch_row(...)

The solution is the following: myHandler must return something in case of error number 8 (Notice), i.e.

  return 0;

What value it returns is not significant: I tested it with true and false and it works in all cases.

The strangest is that when I include the function code of myHandler staticaly (not via a conditional include), it works without the return statement!

The PHP construct list or the function mysql_fetch_row might use this error number for other usage than error reporting and it's a pitty that these details are not listed here in the manual. Not to say it was very hard to find out where the problem was because the problem was inside an error handler and PHP does not allow recursive call to an error handler.
pgerzsonr at freestart dot hu
11-Jan-2002 02:03
A handy errorhandler class can be found at:

http://phpclasses.upperdesign.com/browse.html/package/345

It has several enhancements (report layouts):

* prints the source code fragment where the error encountered,
* prints variable context around error source,
* suppresses error-messages, instead displays an arbitrary HTML or PHP page
* logging to multiple targets and autodetecting target logging
* error messages can be displayed in a separate browser window
* catching errors for runtime generated codes
* debugging variables.

<dotnet_loaddebug_backtrace>
 Last updated: Sun, 02 May 2004
show source | credits | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2004 The PHP Group
All rights reserved.
This mirror generously provided by: Italia OnLine S.p.a.
Last updated: Fri May 21 04:11:23 2004 CEST