Let's take a rough look at the Error_log () function. Let's look at the explanation of the manual:
Error_log
(PHP 3, PHP 4, PHP 5)
BOOL Error_log (String message [, int message_type [, String destination [, String extra_headers]])
Send an error message to the Web server's error log, a TCP port, or a file.
[Separator]
We look at its arguments, the first argument message is the content, the second parameter type is the message type, the third parameter is the destination file, and the fourth parameter is the other header information. In fact, the general fourth parameters are not used, we mainly look at the first three parameters, the second parameter is the message type, including 0, 1, 2, 3 and four types, 0 is the default type. Four functions of a type:
0
Information content is sent to the system log records of PHP, using the operating system's own logging mechanism or a file, depending on the configuration options in the PHP.ini error_log content. This is the default option.
1
Send information to an email address, the third parameter is a mail address, the fourth parameter is a header message to send the message, the second type uses the mail () function to send the message
2
The message passes through the debugging server of PHP, writes to a PHP debugging server remotely, of course, PHP--enable-debugger must open when compiling, in addition, the whole type is only for PHP 3 valid
3
The message is attached to a target file as a new line
In fact, for us, the log for the sake of simplicity, the general direct use of type 3 is more appropriate, the log file to write to their own needs of the file.
For the simple use of the example error_log () function, let's illustrate the example. Let's say that our database abstract class uses pear::D class B, and now I want to record in my program whether there is an execution error in our program. So we use Error_log () to record the execution errors or failures of our SQL statements, at least our pear::D Class B provides a Db::iserror () method to get an execution result object for errors. So we can then break whether or not to execute a certain SQL error, and then consider whether logging, while the object has a UserInfo attribute, which records the wrong SQL statement, then we can construct such a function:
function Logerror ($object)
{
if (Db::iserror ($object))
{
Error_log (Date ("[Y-m-d h:i:s]"). "-[". $_server[' Request_uri ']. ":". $object-> userinfo. " \ n ", 3,"/tmp/php_sql_err.log ");
return true;
}
return false;
}
This function is the ability to record where the error SQL is found, and then automatically log the time, current page, and incorrect SQL statement information into the /tmp/php_sql_err.log file, and when we debug the program, When data extraction is incorrect or no data is extracted, we can view the/tmp/php_sql_err.log file to view our error page and the wrong SQL statement.
Of course, we have to use this function in the program where we execute the SQL query, for example, we execute a function that extracts news information:
function Getnewscontent ($news _id, $field = "")
{
Global $db;
$result = $db->getrow ("Select $field from news WHERE news_id = ' $news _id '");
if (Logerror ($result))
{
return false;
}
return $result;
}
We are inside to determine if the SQL is wrong, if the error returns false, and then we can look at the log to see if our function is running as we expected.
We perform: Tail/tmp/php_sql_err.log
You can see information similar to this:
[2006-01-12 11:44:34]-[/news_list.php?news_id=1]: SELECT from news WHERE news_id = ' 1 ' [nativecode=1064 * * you have a E Rror in your SQL syntax; Check the manual that corresponds to your MySQL server version fo
R the right syntax to use near ' from news WHERE news_id = ' 1 ']
Basically because we select the time, did not need to extract the name of the field, then we can check the news_list.php file, the production getnewscontent () function method does not pass $field parameters into, resulting in SQL execution error. So the Error_log () function helps to check that our SQL is written correctly, or that the parameters are not passed correctly, which greatly reduces the burden of development, but it does a unit test of our program.
Of course, you can also use the Error_log () function to do more logging error log, to facilitate the development of PHP, this is all decided by themselves.
Use it to remember a simple log log in this job
<code>
$address = post (' address ');
$group _add = Explode (', ', $address);
$url = "/usr/local/apache/eyoung/tmp/maillog_". Date ("y-m-d"). ". Log ";
foreach ($group _add as $value)
{
/** {{{Modify by muzhaoyang-2006.12.13-log
* Space-delimited data, recorded data for the write text time canvassing ID contestant ID letter Address
*/
$logstr =date ("H:i:s"). " ". $uid." ". $star _uid." ". $value." \ n ";
Error_log ($LOGSTR, 3, $url);
//}}}
}
</code>