PHP error_log()関数
例
エラーメッセージをWebサーバーのエラーログとメールアカウントに送信します。
<?php
// Send error message to the server log if error connecting to the database
if (!mysqli_connect("localhost","bad_user","bad_password","my_db")) {
error_log("Failed to connect to database!", 0);
}
// Send email to administrator if we run out of FOO
if (!($foo = allocate_new_foo())) {
error_log("Oh no! We are out of FOOs!", 1, "[email protected]");
}
?>
定義と使用法
error_log()関数は、エラーメッセージをログ、ファイル、またはメールアカウントに送信します。
構文
error_log(message, type, destination, headers);
パラメータ値
Parameter | Description |
---|---|
message | Required. Specifies the error message to log |
type | Optional. Specifies where the error message should go.
Possible values:
|
destination | Optional. Specifies the destination of the error message. This value depends on the value of the type parameter |
headers | Optional. Only used if the type parameter is set to 1. Specifies additional headers, like From, Cc, and Bcc. Multiple headers should be separated with a CRLF (\r\n) |
技術的な詳細
戻り値: | 成功するとTRUE。失敗するとFALSE |
---|---|
PHPバージョン: | 4.0以降 |
バイナリセーフ: | 番号 |
PHP変更ログ: | PHP 5.2.7:4の値がtypeパラメーターに追加されました |
PHPエラーリファレンス