把日志实时写入数据库

想把日志实时的写入数据库,只要修改一下日志输出就能够了: php

    # CustomLog ${APACHE_LOG_DIR}/thinksns.access.log combined
    CustomLog "| /var/www/tools/thinksns.log2db.php" combined 数据库

PHP文件以下:
#!/usr/bin/env php
<?php
#$in = fopen('','r');
$log = fopen('/var/www/tools/log','a');
while($row = fgets(STDIN)) {
    fwrite($log, $row);    
}
fclose($log);

只要把$row插入数据库就能够了,必定要保证一秒内能够完成插入
日志是每秒一次经过stdin输入进来 日志

相关文章
相关标签/搜索