Statement: This article is an original article by the author, all of which have been analyzed by the author one by one. I hope you can give me some advice if there is something wrong with it. Imsiren. comarchives617PHP has a powerful log processing function: error_log, which can be used to record errors in our program, such as SQL errors. Through the PHP manual, we can know that this function can be sent to the service
Statement: This article is an original article by the author, all of which have been analyzed by the author one by one. I hope you can give me some advice if there is something wrong with it. Http://imsiren.com/archives/617 PHP has a very powerful log processing function: error_log, we can use it to record errors in our program, such as SQL errors. Through the PHP manual, we can know that this function can be sent to the service
Statement: This article is an original article by the author, all of which have been analyzed by the author one by one. I hope you can give me some advice if there is something wrong with it.
Http://imsiren.com/archives/617
PHP has a very powerful log processing function: error_log,
We can use it to record errors in our program, such as SQL errors.
Through the PHP manual, we can know that this function can send an error log to the server, file, or remote target.
It accepts four parameters:
Error is required. The error message to be logged.
Type is optional. Specifies the error record type.
Possible record types:
0-default. According to the error_log configuration in the php. ini file, errors are sent to the server log system or file.
1-The error is sent to the address in the destination parameter. Only the headers parameter is used for this type.
2-send an error through the PHP debugging connection. This option is only available in PHP 3.
3-The error message is sent to the target string of the file.
Destination is optional. Specifies where to send an error message. The value of this parameter depends on the value of the "type" parameter.
Headers is optional. It is only used when "type" is 1.
Specify additional headers, such as From, Cc, and Bcc. Separated by CRLF (\ r \ n.
Note: The From header must be included when an email is sent. You can use this parameter in the php. ini file.
The error_log function supports four methods to record error logs.
1. To the default file
Type is 0.
According to the error_log configuration in the php. ini file, errors are sent to the server log system or file.
2. Email
Type is 1.
error_log("this is a test string",1,"imsiren@163.com","From:imsiren@163.com");
It can send an email to a specific mailbox. The third parameter is the recipient, and the fourth parameter is the sender's mailbox.
3
The PHP debugging connection is used to send errors. This option is only available in PHP 3.
I have never used
4. Send To File
Type = 3
error_log("this is a test string",3,"/home/admin/log/error_log");
This method is often used to write the specified error content to a file.
========================================================== ==============================================
The following describes how PHP implements error_log.
In the ext/tandard/basic_functions.c file:
PHP_FUNCTION(error_log){ char *message, *opt = NULL, *headers = NULL; int message_len, opt_len = 0, headers_len = 0; int opt_err = 0, argc = ZEND_NUM_ARGS(); long erropt = 0; if (zend_parse_parameters(argc TSRMLS_CC, "s|lss", &message, &message_len, &erropt, &opt, &opt_len, &headers, &headers_len) == FAILURE) { return; } if (argc > 1) { opt_err = erropt; } if (opt_err == 3 && opt) { if (strlen(opt) != opt_len) { RETURN_FALSE; } } if (_php_error_log_ex(opt_err, message, message_len, opt, headers TSRMLS_CC) == FAILURE) { RETURN_FALSE; } RETURN_TRUE;}
This is nothing to say. Check the passed parameters and call the _ php_error_log_ex function.
Let's look at its definition.
PHPAPI int _php_error_log_ex(int opt_err, char *message, int message_len, char *opt, char *headers TSRMLS_DC) /* {{{ */{ php_stream *stream = NULL; switch (opt_err) { case 1: /*send an email */ if (!php_mail(opt, "PHP error_log message", message, headers, NULL TSRMLS_CC)) { return FAILURE; } break; case 2: /*send to an address */ php_error_docref(NULL TSRMLS_CC, E_WARNING, "TCP/IP option not available!"); return FAILURE; break; case 3: /*save to a file */ stream = php_stream_open_wrapper(opt, "a", IGNORE_URL_WIN | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); if (!stream) { return FAILURE; } php_stream_write(stream, message, message_len); php_stream_close(stream); break; case 4: /* send to SAPI */ if (sapi_module.log_message) { sapi_module.log_message(message); } else { return FAILURE; } break; default: php_log_err(message TSRMLS_CC); break; } return SUCCESS;}
Case 1: The php_mail function will send emails Based on the sendmail_path configuration in php. ini;
Case 2: I never used it.
Case 3: write data to a file using the IO function.
Case 4: You can use the sapi to record our log Content.
Default: Write the log to the file according to the error_log configuration ..
Http://imsiren.com/archives/617