아래글에 이어 아파치와 php-cli 를 연계하여 로그를 바로 sql 에 저장한다.
예제이므로 DB 클래스와 에러제어 부분은 따로 표기하지 않는다.
PostgreSQL 기준.
httpd.conf
CustomLog "| /etc/apache2/shjsqllog.php" shjsqllog
CREATE TABLE shjlog (
seq SERIAL NOT NULL,
ip CIDR NOT NULL,
port SMALLINT NOT NULL,
bytes BIGINT NOT NULL,
inbytes BIGINT NOT NULL,
outbytes BIGINT NOT NULL,
protocol VARCHAR(30) NOT NULL,
method VARCHAR(10) NOT NULL,
host VARCHAR(200) NOT NULL,
file VARCHAR(300) NOT NULL,
uri VARCHAR(500) NOT NULL,
status SMALLINT NOT NULL,
phpsessid CHAR(32) NOT NULL,
useragent VARCHAR(200) NOT NULL,
referer VARCHAR(500) NOT NULL,
responsetime INTEGER NOT NULL,
datetime TIMESTAMPTZ NOT NULL,
PRIMARY KEY (seq)
);
CREATE INDEX ip_dex ON shjlog (ip);
CREATE INDEX host_dex ON shjlog (host);
CREATE INDEX uri_dex ON shjlog (uri);
CREATE INDEX phpsessid_dex ON shjlog (phpsessid);
CREATE INDEX useragent_dex ON shjlog (useragent);
CREATE INDEX referer_dex ON shjlog (referer);
#!/usr/bin/php
<?php
include_once 'SHJ/debug.inc.php';
include_once 'SHJ/DB/PDOExt.inc.php';
$db = new SHJPDOExt('pgsql', '/etc/apache2/shjlog.ini');
$fields->ip = '';
$fields->port = '';
$fields->bytes = '';
$fields->inbytes = '';
$fields->outbytes = '';
$fields->protocol = '';
$fields->method = '';
$fields->host = '';
$fields->file = '';
$fields->uri = '';
$fields->status = '';
$fields->phpsessid = '';
$fields->useragent = '';
$fields->referer = '';
$fields->responsetime = '';
$fields->datetime = '';
$stmt = $db->insert('shjlog', $fields);
$fp = fopen('php://stdin', 'r');
while(true) {
$line = fgets($fp, 4096);
if(!preg_match('/^ip:"(.*?)" port:"(.*?)" bytes:"(.*?)" inbytes:"(.*?)" outbytes:"(.*?)" protocol:"(.*?)" method:"(.*?)" host:"(.*?)" file:"(.*?)" uri:"(.*?)" status:"(.*?)" phpsessid:"(.*?)" useragent:"(.*?)" referer:"(.*?)" responsetime:"(.*?)" datetime:"(.*?)"$/s', $line, $matches)) {
continue;
}
$fields->ip = $matches[1];
$fields->port = $matches[2];
$fields->bytes = $matches[3];
$fields->inbytes = $matches[4];
$fields->outbytes = $matches[5];
$fields->protocol = $matches[6];
$fields->method = $matches[7];
$fields->host = $matches[8];
$fields->file = $matches[9];
$fields->uri = $matches[10];
$fields->status = $matches[11];
$fields->phpsessid = $matches[12];
$fields->useragent = $matches[13];
$fields->referer = $matches[14];
$fields->responsetime = $matches[15];
$fields->datetime = $matches[16];
try {
$stmt->exec();
} catch(Exception $e) {
$fp2 = fopen('/etc/apache2/shjlogerr.txt', 'w');
fwrite($fp2, $e->getMessage());
fclose($fp2);
$db = new SHJPDOExt('pgsql', '/etc/apache2/shjlog.ini');
$stmt = $db->insert('shjlog', $fields);
try {
$stmt->exec();
} catch(Exception $e) {}
}
}
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7530 | 10년 전 | 792 | ||
| 7529 |
파랑새1597
|
10년 전 | 1214 | |
| 7528 |
파랑새1597
|
10년 전 | 1315 | |
| 7527 |
integrity7
|
10년 전 | 1400 | |
| 7526 | 10년 전 | 2410 | ||
| 7525 |
다빈치코드777
|
10년 전 | 1103 | |
| 7524 | 10년 전 | 1570 | ||
| 7523 | 10년 전 | 960 | ||
| 7522 |
|
10년 전 | 992 | |
| 7521 |
blackkil
|
10년 전 | 1873 | |
| 7520 | 10년 전 | 1297 | ||
| 7519 |
Gaumi
|
10년 전 | 1082 | |
| 7518 | 10년 전 | 1484 | ||
| 7517 | 10년 전 | 836 | ||
| 7516 | 10년 전 | 1287 | ||
| 7515 | 10년 전 | 1403 | ||
| 7514 |
|
10년 전 | 4486 | |
| 7513 |
멋진남자임
|
10년 전 | 1136 | |
| 7512 |
다빈치코드777
|
10년 전 | 874 | |
| 7511 |
|
10년 전 | 3398 | |
| 7510 | 10년 전 | 1366 | ||
| 7509 | 10년 전 | 1144 | ||
| 7508 | 10년 전 | 716 | ||
| 7507 |
senseme
|
10년 전 | 745 | |
| 7506 |
멋진남자임
|
10년 전 | 1640 | |
| 7505 | 10년 전 | 4009 | ||
| 7504 | 10년 전 | 2144 | ||
| 7503 | 10년 전 | 992 | ||
| 7502 | 10년 전 | 518 | ||
| 7501 | 10년 전 | 1443 | ||
| 7500 | 10년 전 | 1494 | ||
| 7499 | 10년 전 | 3389 | ||
| 7498 | 10년 전 | 1217 | ||
| 7497 |
dethos79
|
10년 전 | 2965 | |
| 7496 | 10년 전 | 2152 | ||
| 7495 | 10년 전 | 870 | ||
| 7494 |
CHAVO
|
10년 전 | 1129 | |
| 7493 | 10년 전 | 2648 | ||
| 7492 | 10년 전 | 1271 | ||
| 7491 | 10년 전 | 1484 | ||
| 7490 | 10년 전 | 2335 | ||
| 7489 | 10년 전 | 2123 | ||
| 7488 |
toptopon
|
10년 전 | 891 | |
| 7487 |
|
10년 전 | 1032 | |
| 7486 | 10년 전 | 3357 | ||
| 7485 | 10년 전 | 1313 | ||
| 7484 | 10년 전 | 1375 | ||
| 7483 | 10년 전 | 1024 | ||
| 7482 | 10년 전 | 652 | ||
| 7481 | 10년 전 | 858 | ||
| 7480 | 10년 전 | 1232 | ||
| 7479 | 10년 전 | 2602 | ||
| 7478 | 10년 전 | 1173 | ||
| 7477 |
멋진남자임
|
10년 전 | 1524 | |
| 7476 |
zeppeto
|
10년 전 | 1143 | |
| 7475 |
200점아빠
|
10년 전 | 912 | |
| 7474 | 10년 전 | 4004 | ||
| 7473 | 10년 전 | 998 | ||
| 7472 |
나르시스1
|
10년 전 | 1244 | |
| 7471 | 10년 전 | 874 | ||
| 7470 | 10년 전 | 1281 | ||
| 7469 |
플라이SINJI
|
10년 전 | 982 | |
| 7468 |
|
10년 전 | 551 | |
| 7467 |
|
10년 전 | 668 | |
| 7466 | 10년 전 | 1119 | ||
| 7465 | 10년 전 | 1186 | ||
| 7464 |
|
10년 전 | 1190 | |
| 7463 | 10년 전 | 1252 | ||
| 7462 |
진짜별사탕
|
10년 전 | 857 | |
| 7461 | 10년 전 | 948 | ||
| 7460 | 10년 전 | 3734 | ||
| 7459 |
멋진남자임
|
10년 전 | 1556 | |
| 7458 |
멋진남자임
|
10년 전 | 482 | |
| 7457 | 10년 전 | 922 | ||
| 7456 | 10년 전 | 764 | ||
| 7455 | 10년 전 | 2160 | ||
| 7454 | 10년 전 | 630 | ||
| 7453 | 10년 전 | 826 | ||
| 7452 |
중국어사이트제작
|
10년 전 | 506 | |
| 7451 | 10년 전 | 905 | ||
| 7450 | 10년 전 | 629 | ||
| 7449 |
울라라라우
|
10년 전 | 952 | |
| 7448 | 10년 전 | 1634 | ||
| 7447 |
멋진남자임
|
10년 전 | 508 | |
| 7446 | 10년 전 | 549 | ||
| 7445 |
네이비칼라
|
10년 전 | 1675 | |
| 7444 |
senseme
|
10년 전 | 1408 | |
| 7443 | 10년 전 | 1342 | ||
| 7442 | 10년 전 | 729 | ||
| 7441 |
멋진남자임
|
10년 전 | 1437 | |
| 7440 | 10년 전 | 910 | ||
| 7439 |
|
10년 전 | 762 | |
| 7438 |
|
10년 전 | 938 | |
| 7437 |
basement
|
10년 전 | 1037 | |
| 7436 |
잘살아보자
|
10년 전 | 1128 | |
| 7435 | 10년 전 | 1087 | ||
| 7434 | 10년 전 | 3791 | ||
| 7433 |
|
10년 전 | 2739 | |
| 7432 |
alexkim
|
10년 전 | 860 | |
| 7431 |
이웃집초보
|
11년 전 | 1312 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기