devilbox/.devilbox/bin/apache-2.4/splitlogs.php

31 lines
689 B
PHP
Raw Normal View History

2016-10-09 16:47:49 +00: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 08:16:09 +00:00
$path = '/var/log/apache-2.4';
2016-10-09 16:47:49 +00:00
$fh_timeout = 30; // 30 sek.
2016-10-10 08:16:09 +00:00
$fd = fopen('php://stdin', 'r');
2016-10-09 16:47:49 +00:00
while (!feof($fd)) {
$row = fgets($fd);
2016-10-10 08:16:09 +00:00
list($vhost, $h, $l, $u, $t, $r, $s, $b, $referrer, $ua) = explode(';', $row, 10);
2016-10-09 16:47:49 +00:00
if (!isset(${$vhost})) {
2016-10-10 08:16:09 +00:00
${$vhost} = fopen($path . '/' . $vhost . '_access.log', 'a+');
2016-10-09 16:47:49 +00:00
}
$lastwrite[$vhost] = time();
2016-10-10 08:16:09 +00:00
fputs(${$vhost}, "$h $l $u $t $r $s $b $referrer $ua");
2016-10-09 16:47:49 +00:00
foreach ($lastwrite as $vhost => $time) {
2016-10-10 08:16:09 +00:00
if ((time() - ($time + 30)) >= 0) {
2016-10-09 16:47:49 +00:00
fclose(${$vhost});
unset(${$vhost});
unset($lastwrite[$vhost]);
}
}
}