<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >error_log</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="Error Handling and Logging Functions" HREF="ref.errorfunc.html"><LINK REL="PREVIOUS" TITLE="error_get_last" HREF="function.error-get-last.html"><LINK REL="NEXT" TITLE="error_reporting" HREF="function.error-reporting.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP 手册</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.error-get-last.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.error-reporting.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.error-log" ></A >error_log</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN47475" ></A ><P > (PHP 3, PHP 4, PHP 5)</P >error_log -- Send an error message somewhere</DIV ><DIV CLASS="refsect1" ><A NAME="AEN47478" ></A ><H2 >说明</H2 >bool <B CLASS="methodname" >error_log</B > ( string message [, int message_type [, string destination [, string extra_headers]]] )<BR ></BR ><P > Sends an error message to the web server's error log, a <ACRONYM CLASS="acronym" >TCP</ACRONYM > port or to a file. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN47497" ></A ><H2 >参数</H2 ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >message</CODE ></DT ><DD ><P > The error message that should be logged. </P ></DD ><DT ><CODE CLASS="parameter" >message_type</CODE ></DT ><DD ><P > Says where the error should go. The possible message types are as follows: </P ><P > <DIV CLASS="table" ><A NAME="AEN47512" ></A ><P ><B >表 1. <B CLASS="function" >error_log()</B > log types</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><TBODY ><TR ><TD >0</TD ><TD > <CODE CLASS="parameter" >message</CODE > is sent to PHP's system logger, using the Operating System's system logging mechanism or a file, depending on what the <A HREF="ref.errorfunc.html#ini.error-log" >error_log</A > configuration directive is set to. This is the default option. </TD ></TR ><TR ><TD >1</TD ><TD > <CODE CLASS="parameter" >message</CODE > is sent by email to the address in the <CODE CLASS="parameter" >destination</CODE > parameter. This is the only message type where the fourth parameter, <CODE CLASS="parameter" >extra_headers</CODE > is used. </TD ></TR ><TR ><TD >2</TD ><TD > <CODE CLASS="parameter" >message</CODE > is sent through the PHP debugging connection. This option is only available if <A HREF="configure.html#configure.enable-debugger" >remote debugging has been enabled</A >. In this case, the <CODE CLASS="parameter" >destination</CODE > parameter specifies the host name or IP address and optionally, port number, of the socket receiving the debug information. This option is only available in PHP 3. </TD ></TR ><TR ><TD >3</TD ><TD > <CODE CLASS="parameter" >message</CODE > is appended to the file <CODE CLASS="parameter" >destination</CODE >. A newline is not automatically added to the end of the <CODE CLASS="parameter" >message</CODE > string. </TD ></TR ></TBODY ></TABLE ></DIV > </P ></DD ><DT ><CODE CLASS="parameter" >destination</CODE ></DT ><DD ><P > The destination. Its meaning depends on the <CODE CLASS="parameter" >message_type</CODE > parameter as described above. </P ></DD ><DT ><CODE CLASS="parameter" >extra_headers</CODE ></DT ><DD ><P > The extra headers. It's used when the <CODE CLASS="parameter" >message_type</CODE > parameter is set to <TT CLASS="literal" >1</TT >. This message type uses the same internal function as <A HREF="function.mail.html" ><B CLASS="function" >mail()</B ></A > does. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN47554" ></A ><H2 >返回值</H2 ><P > 如果成功则返回 <TT CLASS="constant" ><B >TRUE</B ></TT >,失败则返回 <TT CLASS="constant" ><B >FALSE</B ></TT >。 </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN47559" ></A ><H2 >范例</H2 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN47562" ></A ><P ><B >例 1. <B CLASS="function" >error_log()</B > examples</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#FF8000">// Send notification through the server log if we can not<br />// connect to the database.<br /></font><font color="#007700">if (!</font><font color="#0000BB">Ora_Logon</font><font color="#007700">(</font><font color="#0000BB">$username</font><font color="#007700">, </font><font color="#0000BB">$password</font><font color="#007700">)) {<br /> </font><font color="#0000BB">error_log</font><font color="#007700">(</font><font color="#DD0000">"Oracle database not available!"</font><font color="#007700">, </font><font color="#0000BB">0</font><font color="#007700">);<br />}<br /><br /></font><font color="#FF8000">// Notify administrator by email if we run out of FOO<br /></font><font color="#007700">if (!(</font><font color="#0000BB">$foo </font><font color="#007700">= </font><font color="#0000BB">allocate_new_foo</font><font color="#007700">())) {<br /> </font><font color="#0000BB">error_log</font><font color="#007700">(</font><font color="#DD0000">"Big trouble, we're all out of FOOs!"</font><font color="#007700">, </font><font color="#0000BB">1</font><font color="#007700">,<br /> </font><font color="#DD0000">"operator@example.com"</font><font color="#007700">);<br />}<br /><br /></font><font color="#FF8000">// other ways of calling error_log():<br /></font><font color="#0000BB">error_log</font><font color="#007700">(</font><font color="#DD0000">"You messed up!"</font><font color="#007700">, </font><font color="#0000BB">2</font><font color="#007700">, </font><font color="#DD0000">"127.0.0.1:7000"</font><font color="#007700">);<br /></font><font color="#0000BB">error_log</font><font color="#007700">(</font><font color="#DD0000">"You messed up!"</font><font color="#007700">, </font><font color="#0000BB">2</font><font color="#007700">, </font><font color="#DD0000">"loghost"</font><font color="#007700">);<br /></font><font color="#0000BB">error_log</font><font color="#007700">(</font><font color="#DD0000">"You messed up!"</font><font color="#007700">, </font><font color="#0000BB">3</font><font color="#007700">, </font><font color="#DD0000">"/var/tmp/my-errors.log"</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.error-get-last.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >起始页</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.error-reporting.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >error_get_last</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.errorfunc.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >error_reporting</TD ></TR ></TABLE ></DIV ></BODY ></HTML >