<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Send an error message to the defined error handling routines</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.error-get-last.html">error_get_last</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.error-reporting.html">error_reporting</a></div> <div class="up"><a href="ref.errorfunc.html">Error Handling Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.error-log" class="refentry"> <div class="refnamediv"> <h1 class="refname">error_log</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">error_log</span> — <span class="dc-title">Send an error message to the defined error handling routines</span></p> </div> <div class="refsect1 description" id="refsect1-function.error-log-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><strong>error_log</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$message</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$message_type</code><span class="initializer"> = 0</span></span> [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$destination</code></span> [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$extra_headers</code></span> ]]] )</div> <p class="para rdfs-comment"> Sends an error message to the web server's error log or to a file. </p> </div> <div class="refsect1 parameters" id="refsect1-function.error-log-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">message</code></em></span> <dd> <p class="para"> The error message that should be logged. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">message_type</code></em></span> <dd> <p class="para"> Says where the error should go. The possible message types are as follows: </p> <p class="para"> <table class="doctable table"> <caption><strong> <span class="function"><strong>error_log()</strong></span> log types</strong></caption> <tbody class="tbody"> <tr> <td>0</td> <td> <em><code class="parameter">message</code></em> is sent to PHP's system logger, using the Operating System's system logging mechanism or a file, depending on what the <a href="errorfunc.configuration.html#ini.error-log" class="link">error_log</a> configuration directive is set to. This is the default option. </td> </tr> <tr> <td>1</td> <td> <em><code class="parameter">message</code></em> is sent by email to the address in the <em><code class="parameter">destination</code></em> parameter. This is the only message type where the fourth parameter, <em><code class="parameter">extra_headers</code></em> is used. </td> </tr> <tr> <td>2</td> <td> No longer an option. </td> </tr> <tr> <td>3</td> <td> <em><code class="parameter">message</code></em> is appended to the file <em><code class="parameter">destination</code></em>. A newline is not automatically added to the end of the <em><code class="parameter">message</code></em> string. </td> </tr> <tr> <td>4</td> <td> <em><code class="parameter">message</code></em> is sent directly to the SAPI logging handler. </td> </tr> </tbody> </table> </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">destination</code></em></span> <dd> <p class="para"> The destination. Its meaning depends on the <em><code class="parameter">message_type</code></em> parameter as described above. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">extra_headers</code></em></span> <dd> <p class="para"> The extra headers. It's used when the <em><code class="parameter">message_type</code></em> parameter is set to <em>1</em>. This message type uses the same internal function as <span class="function"><a href="function.mail.html" class="function">mail()</a></span> does. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.error-log-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure. </p> </div> <div class="refsect1 notes" id="refsect1-function.error-log-notes"> <h3 class="title">Notes</h3> <div class="warning"><strong class="warning">Warning</strong> <p class="simpara"> <span class="function"><strong>error_log()</strong></span> is not binary safe. <em><code class="parameter">message</code></em> will be truncated by null character. </p> </div> <div class="tip"><strong class="tip">Tip</strong> <p class="simpara"> <em><code class="parameter">message</code></em> should not contain null character. Note that <em><code class="parameter">message</code></em> may be sent to file, mail, syslog, etc. Use appropriate conversion/escape function, <span class="function"><a href="function.base64-encode.html" class="function">base64_encode()</a></span>, <span class="function"><a href="function.rawurlencode.html" class="function">rawurlencode()</a></span> or <span class="function"><a href="function.addslashes.html" class="function">addslashes()</a></span> before calling <span class="function"><strong>error_log()</strong></span>. </p> </div> </div> <div class="refsect1 examples" id="refsect1-function.error-log-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-452"> <p><strong>Example #1 <span class="function"><strong>error_log()</strong></span> examples</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// Send notification through the server log if we can not<br />// connect to the database.<br /></span><span style="color: #007700">if (!</span><span style="color: #0000BB">Ora_Logon</span><span style="color: #007700">(</span><span style="color: #0000BB">$username</span><span style="color: #007700">, </span><span style="color: #0000BB">$password</span><span style="color: #007700">)) {<br /> </span><span style="color: #0000BB">error_log</span><span style="color: #007700">(</span><span style="color: #DD0000">"Oracle database not available!"</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #FF8000">// Notify administrator by email if we run out of FOO<br /></span><span style="color: #007700">if (!(</span><span style="color: #0000BB">$foo </span><span style="color: #007700">= </span><span style="color: #0000BB">allocate_new_foo</span><span style="color: #007700">())) {<br /> </span><span style="color: #0000BB">error_log</span><span style="color: #007700">(</span><span style="color: #DD0000">"Big trouble, we're all out of FOOs!"</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">"operator@example.com"</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #FF8000">// another way to call error_log():<br /></span><span style="color: #0000BB">error_log</span><span style="color: #007700">(</span><span style="color: #DD0000">"You messed up!"</span><span style="color: #007700">, </span><span style="color: #0000BB">3</span><span style="color: #007700">, </span><span style="color: #DD0000">"/var/tmp/my-errors.log"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 changelog" id="refsect1-function.error-log-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>5.2.7</td> <td> The possible value of 4 was added to <em><code class="parameter">message_type</code></em>. </td> </tr> </tbody> </table> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.error-get-last.html">error_get_last</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.error-reporting.html">error_reporting</a></div> <div class="up"><a href="ref.errorfunc.html">Error Handling Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>