PHP error_log()Functions


PHP Error 参考手册Complete PHP Error Reference Manual

Definition and Usage

The error_log() function sends an error to the server error log, a file, or a remote destination.

Returns TRUE on success, or FALSE on failure.

Syntax

error_log(error,type,destination,headers)

Parameters Description
error Required. The error message to be logged.
type Optional. Specifies the type of error logging.
Possible logging types:
  • 0 - Default. The error is sent to the server logging system or a file according to the error_log configuration in the php.ini file.
  • 1 - The error is sent to the address in the destination parameter. Only this type uses the headers parameter.
  • 2 - The error is sent through a PHP debugging connection. This option is only available in PHP 3.
  • 3 - The error is sent to the file destination string.
destination Optional. Specifies where to send the error message. The value of this parameter depends on the value of the "type" parameter.
headers Optional. Only used when the "type" parameter is 1. Specifies additional headers, such as From, Cc, and Bcc. Additional headers are separated by CRLF (\r\n).

Note:When sending an email, the From header must be included. It can be set in the php.ini file or through this parameter.



Examples

The following example sends an email with a custom error:

<?php
$test=2;

if ($test>1)
{
error_log("A custom error has been triggered",
1,"someone@example.com","From: webmaster@example.com");
}
?>

The email received by the above code is as follows:

A custom error has been triggered


PHP Error 参考手册Complete PHP Error Reference Manual Other Extensions