Parameters

Says where the error should go. The possible message types are as
follows:

error_log() log types

0

message is sent to PHP's system logger, using
the Operating System's system logging mechanism or a file, depending
on what the error_log
configuration directive is set to. This is the default option.

1

message is sent by email to the address in
the destination parameter. This is the only
message type where the fourth parameter,
extra_headers is used.

2

No longer an option.

3

message is appended to the file
destination. A newline is not automatically
added to the end of the message string.

4

message is sent directly to the SAPI logging
handler.

destination

The destination. Its meaning depends on the
message_type parameter as described above.

extra_headers

The extra headers. It's used when the message_type
parameter is set to 1.
This message type uses the same internal function as
mail() does.

Return Values

Returns TRUE on success or FALSE on failure.

Notes

Warning

error_log() is not binary safe. message will be truncated by null character.

Tip

message should not contain null character. Note that message may be sent to file, mail, syslog, etc. Use appropriate conversion/escape function, base64_encode(), rawurlencode() or addslashes() before calling error_log().

Examples

Example #1 error_log() examples

<?php// Send notification through the server log if we can not// connect to the database.if (!Ora_Logon($username, $password)) {error_log("Oracle database not available!", 0);}

// Notify administrator by email if we run out of FOOif (!($foo = allocate_new_foo())) {error_log("Big trouble, we're all out of FOOs!", 1,"operator@example.com");}

// another way to call error_log():error_log("You messed up!", 3, "/var/tmp/my-errors.log");?>

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.

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.

When logging to apache on windows, both error_log and also trigger_error result in an apache status of error on the front of the message. This is bad if all you want to do is log information. However you can simply log to stderr however you will have to do all message assembly:

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.

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!

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

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.

This had me hunting for a while till I figured this out. What ever folder you want your logs deposited to, don't create the log file yourself, let php do it for you. For some reason, if the log file already exists and it's 0 KB, PHP will try to re-create the log file and fail in the process. It never attempts to write to the pre-existing empty file, just fails on folder creation. Might be do to the folder permissions I have on windows, but this is what I found with read/write/modify permissions for IIS_IUSRS on Win2008. Once PHP has written to its self-created file successfully, it will append to the file on new errors. Process Monitor is my friend :)

When starting Apache from a user context other than Apache's runtime user, the error log file (if one is specified) may be created under the starting user if it did not previously exist.

For example, I had specified the incorrect filename for my browscap.ini file, and would only see this error in the log file upon each restart of Apache. Because of this, I assumed I'd configured logging correctly:

[24-Feb-2010 12:33:04] PHP Warning: Cannot open '/etc/php5/apache/lite_php_browscap.ini' for reading in Unknown on line 0

No other errors would log at runtime even though I had originally set the owner of the log directory to www-data (Apache runs under this user context). My file (error.log) was being created with the owner = root, because I had restarted the apache2 service as root after configuring the log file location. (I made the poor assumption that since PHP/Apache had created the file it was created by www-data, so I hadn't looked).

Changing owner of the log file to the correct user (i.e. www-data) fixed the problem.

After scouring the internet for getting event logging to work in syslog on Windows 2003, I found the following from this post and was able to successfully get Windows Event Viewer to log PHP errors/notices:

1. Copy the PHP 5 binaries to "C:\php". 2. Right-click My Computer and select Properties to bring up the Computer Properties dialog. Switch to the Advanced tab and click Environment Variables. Find the system environment variable PATH, edit it and add ";C:\php" (without the quotes) to the end. 3. Make sure that the configuration file "php.ini" resides in the directory "C:\php" and contains the correct path settings. 4. DELETE any old "php.ini" files from "C:\WINDOWS" and other directories. 5. Open REGEDIT, navigate to the key "HKLM\SOFTWARE\PHP" and DELETE the string value "IniFilePath" from there. It is outdated and no longer necessary! 6. Modify NTFS security permissions of the directory "C:\php" to give Read and Execute permissions to (1) the IIS Guest Account and (2) the group IIS_WPG. 7. Modify NTFS security permissions of the directories "C:\php\session" and "C:\php\upload" to give additional Modify permissions to (1) the IIS Guest Account and (2) the group IIS_WPG. 8. Navigate to the registry key "HKLM\SYSTEM\CurrentControlSet\Services\Eventlog\Application" and edit the value "CustomSD" there. Find the substring "(D;;0xf0007;;;BG)" which Denies access to the application event log for Builtin Guest accounts (like the IIS Web User account) and replace this substring with "(A;;0x3;;;BG)" which allows read and write access. Please pay attention to leave the rest of the security string intact. Damaging this value can have dangerous effects! 9. Create or update the registry key "HKLM\SYSTEM\CurrentControlSet\Services\Eventlog\Application\PHP-5.2.0" (adapt the last to your version part if necessary) with the following values: