把日誌實時寫入數據庫

想把日誌實時的寫入數據庫,只要修改一下日誌輸出就能夠了: 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輸入進來 日誌

相關文章
相關標籤/搜索