Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
PHP: error_log - Manual
[go: Go Back, main page]

PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

error_reporting" width="11" height="7"/> <error_get_last
Last updated: Fri, 30 May 2008

view this page in

error_log

(PHP 4, PHP 5)

error_log — エラーメッセージを送信する

説明

bool error_log ( string $message [, int $message_type [, string $destination [, string $extra_headers ]]] )

エラーメッセージを Web サーバのエラーログ、 TCP ポート、あるいはファイルに送ります。

パラメータ

message

ログに記録されるエラーメッセージ。

message_type

メッセージをどこに送るのかを指定します。以下の中から指定できます。

error_log() ログタイプ
0 message は、オペレーティング・システム のシステムログのメカニズムまたはファイルのいずれかを使って PHP のシステム・ロガーに送られます。どちらが使われるかは、 設定ディレクティブ error_log の内容により決定されます。これはデフォルトのオプションです。
1 message は、destination パラメータで指定されたアドレスに、電子メール により送られます。このメッセージタイプの場合にのみ、 4 番目のパラメータである extra_headers が使われます。
2 このオプションは存在しません。
3 messagedestination で指定されたファイルに追加されます。 明示的に指定しない限り、message の 最後には改行文字は追加されません。

destination

メッセージの送信先。その設定は、上で説明している message_type パラメータの値によります。

extra_headers

追加のヘッダ。message_type パラメータが 1 に設定される場合に利用されます。 このメッセージタイプは、mail() と同様に 内部関数を利用します。

返り値

成功した場合に TRUE を、失敗した場合に FALSE を返します。

例1 error_log() の例

<?php
// データベースに接続できない場合、
// サーバログを通してエラーを通知する。
if (!Ora_Logon($username$password)) {
    
error_log("オラクルのデータベースが使用できません!"0);
}

// FOO に失敗したら、管理者に email で通知する
if (!($foo allocate_new_foo())) {
    
error_log("大変です。FOO に失敗しました!"1,
               
"operator@example.com");
}

// これ以外の error_log() のコール方法:
error_log("大変だ!"3"/var/tmp/my-errors.log");
?>



error_reporting" width="11" height="7"/> <error_get_last
Last updated: Fri, 30 May 2008
 
add a note add a note User Contributed Notes
error_log
i dot buttinoni at intandtel dot com
16-Feb-2008 08:32
Be carefull. Unexpected PHP dies when 2GByte of file log reached (on systems having upper file size limit).
A work aorund is rotate logs :)
SJL
01-Jan-2008 11:16
"It appears that the system log = stderr if you are running PHP from the command line"

Actually, it seems that PHP logs to stderr if it can't write to the log file. Command line PHP falls back to stderr because the log file is (usually) only writable by the webserver.
larry.kooper at gmail dot com
12-Oct-2007 07:00
On a Mac running OS X, for the error logging to work I needed to put this in my php.ini:
error_log = /tmp/php_errors.log
Attempting to put the log in other locations did not work, probably due to permission issues.
stepheneliotdewey at GmailDotCom
27-Jun-2007 10:05
Note that since typical email is unencrypted, sending data about your errors over email using this function could be considered a security risk. How much of a risk it is depends on how much and what type of information you are sending, but the mere act of sending an email when something happens (even if it cannot be read) could itself imply to a sophisticated hacker observing your site over time that they have managed to cause an error.

Of course, security through obscurity is the weakest kind of security, as most open source supporters will agree. This is just something that you should keep in mind.

And of course, whatever you do, make sure that such emails don't contain sensitive user data.
frank at booksku dot com
03-Nov-2006 08:28
Beware!  If multiple scripts share the same log file, but run as different users, whichever script logs an error first owns the file, and calls to error_log() run as a different user will fail *silently*!

Nothing more frustrating than trying to figure out why all your error_log calls aren't actually writing, than to find it was due to a *silent* permission denied error!
p dot lhonorey at nospam-laposte dot net
28-Aug-2006 07:33
Hi !

Another trick to post "HTML" mail body. Just add "Content-Type: text/html; charset=ISO-8859-1" into extra_header string. Of course you can set charset according to your country or Env or content.

EG: Error_log("<html><h2>stuff</h2></html>",1,"eat@joe.com","subject  :lunch\nContent-Type: text/html; charset=ISO-8859-1");

Enjoy !
marques at displague dot com
27-Aug-2005 05:52
Beware the size of your custom error_log!

Once it exceeds 2GB the function errors, ending your script at the error_log() line.  I'm sure this differs from OS to OS, but I have seen it die writing to ext2 under modern Linux systems.
mac at codegreene dot com
09-Aug-2005 01:33
When outputting to syslog, it uses the syslog() function, which limits its output to 500 characters. We have been able to send multi-line output to the log, but newlines appear to be replaced with a space in the output, and output is cut off at 500 characters.

A simple workaround for long, multi-line output is something like this:

$errlines = explode("\n",$errmsg);
foreach ($errlines as $txt) { error_log($txt); }
php at kennel17 dot NOSPAM dot co dot uk
26-Jul-2005 06:04
It appears that the system log = stderr if you are running PHP from the command line, and that often stderr = stdout.  This means that if you are using a custom error to both display the error and log it to syslog, then a command-line user will see the same error reported twice.
kazezb at nospam dot carleton dot edu
22-Jul-2005 02:39
It appears that error_log() only logs the first line of multi-line log messages. To log a multi-line message, either log each line individually or write the message to another file.
franz at fholzinger dot com
21-Apr-2005 01:21
In the case of missing your entries in the error_log file:
When you use error_log in a script that does not produce any output, which means that you cannot see anything during the execution of the script, and when you wonder why there are no error_log entries produced in your error_log file, the reasons can be:
- you did not configure error_log output in php.ini
- the script has a syntax error and did therefore not execute
29-Mar-2003 07:14
when using error_log to send email, not all elements of an extra_headers string are handled the same way.  "From: " and "Reply-To: " header values will replace the default header values. "Subject: " header values won't: they are *added* to the mail header but don't replace the default, leading to mail messages with two Subject fields.

<?php

error_log
("sometext", 1, "zigzag@my.domain",
 
"Subject: Foo\nFrom: Rizzlas@my.domain\n");

?>

---------------%<-----------------------
To: zigzag@my.domain
Envelope-to: zigzag@my.domain
Date: Fri, 28 Mar 2003 13:29:02 -0500
From: Rizzlas@my.domain
Subject: PHP error_log message
Subject: Foo
Delivery-date: Fri, 28 Mar 2003 13:29:03 -0500

sometext
---------------%<---------------------

quoth the docs: "This message type uses the same internal function as mail() does." 

mail() will also fail to set a Subject field based on extra_header data - instead it takes a seperate argument to specify a "Subject: " string.

php v.4.2.3, SunOS 5.8
dan at mojavelinux dot com
01-Feb-2003 04:46
I find it very suprising that there are no PHP constants (or references to them if they exist) for the log types.  I would expect

SYSTEM_LOG = 0
TCP_LOG = 1
FILE_LOG = 2
MAIL_LOG = 3

or something to that nature.  Are we going to see this in any future versions?  Seems very silly to use integers here when they could easily be changed or confused.

error_reporting" width="11" height="7"/> <error_get_last
Last updated: Fri, 30 May 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites