Logging PHP to Windows Event Log
PHP allows you two methods of logging PHP events using the error_log directive in php.ini. A typical set up would be to configure PHP to log to a flat file, by setting the error_log value to the full path and file name to your php log file. For smaller environments this might be fine, however if you're using a event log monitoring agent to report and monitor server operations centrally this may not be ideal as all you PHP related events will be missed. In this guide we'll look at how you can configure PHP so it logs events to your Windows application event log rather than to a flat file.
In previous versions of PHP it was could be quite troublesome to get PHP to log to the Windows Event Log, and often required alterating the permissions on the event log files themselves so IIS could write to them. With PHP 5.2 it is actually very easy nowadays to get PHP to log to your Windows Event Log. Simply open your php.ini file with your favourite text editor and replace;
log_errors = Off
log_errors = On
This will turn on PHP logging in PHP. Next step is to direct PHP to log events to your Windows Event Log by finding this;
;error_log = syslog
And replacing it with;
error_log = syslog
Although syslog is actually the *nix equivalent of the Windows Event Log we still need to specify it here as PHP does not differentiate between the two, however PHP will know to log to the Windows Event Log when being used on a Windows System. With that done save your php.ini file and recycle the IIS application pools using PHP, and you should now start seeing PHP events being logged to your Windows Application Log in Event Viewer.
One final setting you may wish to tweak in your php.ini file is the error_reporting directive. This setting specifies the level of logging PHP does, and by default is set to show all errors except coding standards warnings. There are several levels of logging that can be set, and they can be combined or explicitly denied depending on your requirements. Refer to the notes in your php.ini file for more information.
Hopefully this guide has helped someone. If you have any comments or feedback on this article, please feel free to post here. If you have a specific support requirement please post in the forums for free support (best effort support only), or use the contact form if you wish to contact me regarding fee based consulting.