LogPipe is a PHP extension module that extends the default PHP error messages with additional information and allows you to pipe the logs to an external program or write them to a syslog facility.
When a user connects to a PHP website hosted on a cloud platform like vCluster, the response may come from different web servers running on different virtual and physical machines. This introduced the problem of needing to aggregate the PHP error logs from different cluster nodes and then split them up again based on the virtual host. Unfortunately the default PHP error message handler does not provide the information or ability to pipe the error logs to an external program, unlike the CustomLog directive in Apache does.
Here at CatN, we have already solved the problem of web log file processing on the cloud using TCPWebLog but the default PHP error handling does not provide enough information to feed this system, nor does it allow logs to be directly piped into it.
In order to overcome these issues I decided to create LogPipe, an Open Source PHP extension module. Once loaded, when a PHP error is triggered, LogPipe prefixes the error message with the IP and hostname of the virtual host. It then adds the IP of the client before piping the output to and external program (i.e. TCPWebLog) or sending it to a syslog facility. Then the default PHP error handler is called.
The new LogPipe PHP error log format is:
VHOST_IP VHOST_NAME [LOG_TIME_STR] PHP ERROR_TYPE_DESC: ERROR_DESC in ERROR_FILENAME on line ERROR_LINENO [client CLIENT_IP
- VHOST_IP : ($_SERVER['SERVER_ADDR']) the IP address of the server (virtual host) under which the current script is executing.
- VHOST_NAME : ($_SERVER['HTTP_HOST']) the host name of the server (virtual host) under which the current script is executing.
- CLIENT_IP : ($_SERVER['REMOTE_ADDR']) the client IP address.
- LOG_TIME_STR: log date-time.
- ERROR_TYPE_DESC: type of error.
- ERROR_DESC: error description.
- ERROR_FILENAME: the current php script file name were the error originated.
- ERROR_LINENO: number of the line on the current php script file were the error originated.
18.104.22.168 example.com [10-Apr-2013 12:34:56] PHP Notice: Undefined variable: x in /var/www/test.php on line 6 [client 22.214.171.124]
COMPILE AND INSTALL
Before you start, make sure you have the PHP development package installed in your system:
on RHEL-like systems:
yum install php-devel
on Debian-like systems:
sudo apt-get install php5-dev
Note: on the examples below the file paths are relative to a RHEL Operating System, so they may vary depending by the OS you are using.
1. get the LogPipe source code:
cd ~ git clone git://github.com/fubralimited/LogPipe.git
2. compile the LogPipe module:
cd ~/LogPipe phpize ./configure --enable-logpipe make
3. copy the LogPipe module on the PHP module directory:
cp ./modules/logpipe.so /usr/lib64/php/modules/
4. copy and edit the LogPipe configuration INI file:
cp logpipe.ini /etc/php.d/ vi /etc/php.d/logpipe.ini
disable the module:
; MODULE DISABLED extension=/usr/lib64/php/modules/logpipe.so logpipe.mode=0 logpipe.command=""
send logs to syslog:
; SYSLOG extension=/usr/lib64/php/modules/logpipe.so logpipe.mode=1 logpipe.command="local4"
pipe logs to TCPWebLog:
; TCPWEBLOG (check the TCPWebLog documentation for the correct parameters) extension=/usr/lib64/php/modules/logpipe.so logpipe.mode=2 logpipe.command="/usr/bin/tcpweblog_client.bin 10.0.2.15 9940 /var/log/tcpweblog_cache.log php.log 1 - -"
The PHP reporting level can be set as usual using the php.ini directive error_reporting.
5. Restart syslog-ng (only if you are using the syslog mode):
service syslog-ng restart
6. Restart Apache:
For additional information on this project please visit the LogPipe project on GitHub repository.
Feel free to try this extension module and leave your comments and suggestions here to help develop the project further.