PHP for apache logging to mysql
| From: | Ronan Chilvers | Date: | Thu, 27 Mar 2003 15:09:49 +0000 |
| Subject: | PHP for apache logging to mysql | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-26656@lists.php.net to get a copy of this message | ||
Hi folks
Ronan here. Just joined the list. I do PHP / MYSQL / GD / HTML / JavaScript / Flash stuff,
building db driven sites, content management systems, etc. I also use PHP as a scripting langauge
on my servers - its generally great.
However I have a little problem which someone might have come across or be able to shed some light
on. I want to pipe logs directly from apache into mysql. At the moment I can do this using a perl
script that does this sort of thing:-
<script>
#!/usr/bin/perl
[ DB CONNECTIONS etc ]
while (<STDIN>) {
[ DO DB INSERTS HERE ]
}
[ DB OBJ CLOSURE etc ]
</script>
I'm doing this in PHP:-
<script>
#!/usr/bin/php -q
<?php
$fp = fopen("/dev/stdin","r");
$inputfp = fopen("./input.txt","a");
function write_input($input, $inputfp) {
[ DB INSERTS HERE ]
}
$input = fread($fp,4096); // 4096 arbitrary value for testing
write_input($input,$inputfp);
fclose($inputfp);
fclose($fp);
?>
</script>
Works great if I manually pipe from ls or something
(ie: ls ~/ | phplog.php) but nothing happens when piping from apache. I reckon that the problem
lies in the file pointer reading - perl seems to keep the pointer (ie: pipe) open while php seems to
close the pipe after each fread().
Any clues ???
Cheers
--
Ronan
e: ronan@thelittledot.com
t: 01903 739 997
w: www.thelittledot.com
The Little Dot is a partnership of
Ronan Chilvers and Giles Webberley