Source of: /manual/en/function.error-log.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.errorfunc.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'function.error-log.php',
1 => 'error_log',
),
'up' =>
array (
0 => 'ref.errorfunc.php',
1 => 'Error Handling Functions',
),
'prev' =>
array (
0 => 'function.error-get-last.php',
1 => 'error_get_last',
),
'next' =>
array (
0 => 'function.error-reporting.php',
1 => 'error_reporting',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<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 somewhere</span></p>
</div>
<a name="function.error-log.description"></a><div class="refsect1 description">
<h3 class="title">Description</h3>
<div class="methodsynopsis dc-description">
<span class="type">bool</span> <span class="methodname"><b>error_log</b></span>
( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$message</tt></span>
[, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$message_type</tt><span class="initializer"> = 0</span></span>
[, <span class="methodparam"><span class="type">string</span> <tt class="parameter">$destination</tt></span>
[, <span class="methodparam"><span class="type">string</span> <tt class="parameter">$extra_headers</tt></span>
]]] )</div>
<p class="para rdfs-comment">
Sends an error message to the web server's error log, a
<acronym title="Transmission Control Protocol">TCP</acronym> port or to a file.
</p>
</div>
<a name="function.error-log.parameters"></a><div class="refsect1 parameters">
<h3 class="title">Parameters</h3>
<p class="para">
</p><dl>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">message</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
The error message that should be logged.
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">message_type</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
Says where the error should go. The possible message types are as
follows:
</p>
<p class="para">
</p><table class="doctable table">
<caption><b><b>error_log()</b> log types</b></caption>
<tbody valign="middle" class="tbody">
<tr valign="middle">
<td align="left">0</td>
<td align="left">
<i><tt class="parameter">message</tt></i>
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.php#ini.error-log" class="link">error_log</a>
configuration directive is set to. This is the default option.
</td>
</tr>
<tr valign="middle">
<td align="left">1</td>
<td align="left">
<i><tt class="parameter">message</tt></i>
is sent by email to the address in
the <i><tt class="parameter">destination</tt></i>
parameter. This is the only
message type where the fourth parameter,
<i><tt class="parameter">extra_headers</tt></i>
is used.
</td>
</tr>
<tr valign="middle">
<td align="left">2</td>
<td align="left">
No longer an option.
</td>
</tr>
<tr valign="middle">
<td align="left">3</td>
<td align="left">
<i><tt class="parameter">message</tt></i>
is appended to the file
<i><tt class="parameter">destination</tt></i>
. A newline is not automatically
added to the end of the <i><tt class="parameter">message</tt></i>
string.
</td>
</tr>
<tr valign="middle">
<td align="left">4</td>
<td align="left">
<i><tt class="parameter">message</tt></i>
is sent directly to the SAPI logging
handler.
</td>
</tr>
</tbody>
</table>
<p>
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">destination</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
The destination. Its meaning depends on the
<i><tt class="parameter">message_type</tt></i>
parameter as described above.
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">extra_headers</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
The extra headers. It's used when the <i><tt class="parameter">message_type</tt></i>
parameter is set to <i>1</i>.
This message type uses the same internal function as
<a href="function.mail.php" class="function">mail()</a> does.
</p>
</dd>
</dl>
<p>
</p>
</div>
<a name="function.error-log.returnvalues"></a><div class="refsect1 returnvalues">
<h3 class="title">Return Values</h3>
<p class="para">
Returns <b><tt class="constant">TRUE</tt></b> on success or <b><tt class="constant">FALSE</tt></b> on failure.
</p>
</div>
<a name="function.error-log.changelog"></a><div class="refsect1 changelog">
<h3 class="title">Changelog</h3>
<p class="para">
</p><table class="doctable informaltable">
<thead valign="middle">
<tr valign="middle">
<th>Version</th>
<th>Description</th>
</tr>
</thead>
<tbody valign="middle" class="tbody">
<tr valign="middle">
<td align="left">5.2.7</td>
<td align="left">
The possible value of 4 was added to <i><tt class="parameter">message_type</tt></i>
.
</td>
</tr>
</tbody>
</table>
<p>
</p>
</div>
<a name="function.error-log.examples"></a><div class="refsect1 examples">
<h3 class="title">Examples</h3>
<p class="para">
</p><div class="example">
<p><b>Example #1 <b>error_log()</b> examples</b></p>
<div class="example-contents programlisting">
<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>
</p>
</div>
</div><?php manual_footer(); ?>