Current Location: Home> Function Categories> error_log

error_log

Send an error message somewhere
Name:error_log
Category:Error handling
Programming Language:php
One-line Description:Send an error message to the server error record, file, or remote target.

Definition and usage

error_log() function sends an error message to the server error log, file, or remote target.

Example

Send error messages to the web server log and email account:

 <?php
// If the error is connected to the database, an error message is sent to the server log
if ( ! mysqli_connect ( "localhost" , "bad_user" , "bad_password" , "my_db" ) ) {
    error_log ( "Failed to connect to database!" , 0 ) ;
}

// If you run out of FOO, send an email to the administrator
if ( ! ( $foo = allocate_new_foo ( ) ) ) {
    error_log ( "Oh no! We are out of FOOs!" , 1 , "admin@example.com" ) ;
}
?> 

grammar

 error_log ( message , type , destination , headers ) ;
parameter describe
message Required. Specifies the error message to be recorded.
type

Optional. Specify where errors should be sent. Possible values:

  • 0 - Default. The message is sent to the PHP system log, using the operating system log mechanism or a file, depending on the error_log directive in php.ini.
  • 1 - The message is sent to the email address set by the destination parameter. The fourth parameter extra_headers will only be used in this type.
  • 2 - No longer used (only in PHP 3)
  • 3 - The message is sent to a file with destination location. The character message will not be treated as a new line by default.
  • 4 - The message is sent directly to the SAPI log handler.
destination Optional. Specify the target of the error message. This value is determined by the value of the type parameter.
Headers

Optional. Specify additional headers such as From, Cc and Bcc. This information type uses the same built-in function of mail().

Only used when message_type is set to 1.

CRLF (\r\n) should be used to separate multiple headers.

Similar Functions
Popular Articles