31 lines
689 B
PHP
Raw Normal View History

2016-10-09 18:47:49 +02:00
#!/usr/bin/env php
<?php
// TODO: logpath could also be passed via CMD argument
// so this script could be more general
2016-10-10 10:16:09 +02:00
$path = '/var/log/apache-2.4';
2016-10-09 18:47:49 +02:00
$fh_timeout = 30; // 30 sek.
2016-10-10 10:16:09 +02:00
$fd = fopen('php://stdin', 'r');
2016-10-09 18:47:49 +02:00
while (!feof($fd)) {
$row = fgets($fd);
2016-10-10 10:16:09 +02:00
list($vhost, $h, $l, $u, $t, $r, $s, $b, $referrer, $ua) = explode(';', $row, 10);
2016-10-09 18:47:49 +02:00
if (!isset(${$vhost})) {
2016-10-10 10:16:09 +02:00
${$vhost} = fopen($path . '/' . $vhost . '_access.log', 'a+');
2016-10-09 18:47:49 +02:00
}
$lastwrite[$vhost] = time();
2016-10-10 10:16:09 +02:00
fputs(${$vhost}, "$h $l $u $t $r $s $b $referrer $ua");
2016-10-09 18:47:49 +02:00
foreach ($lastwrite as $vhost => $time) {
2016-10-10 10:16:09 +02:00
if ((time() - ($time + 30)) >= 0) {
2016-10-09 18:47:49 +02:00
fclose(${$vhost});
unset(${$vhost});
unset($lastwrite[$vhost]);
}
}
}