Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

i have a piped logging program like this:

#!/usr/bin/php
<?php

$fd = fopen("php://stdin", "r");
while(true) {
  $l = fread($fd,8192);
  $l = trim($l);
  if($l =="") continue;
  file_put_contents('/home/proxy/testfile',$l."\n", FILE_APPEND);
}
fclose($fd);

and in my webserver config i have:

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" proxylog
CustomLog "|/home/proxy/logger.php" proxylog

the weird thing is that i do recieve some log input that is written, but only very rarely. far less than in the default log file. i also cant recognise a pattern.

i also waited long enough and successfully checked for missing log lines from a time frame before the last log entry in my custom piped log - to eliminiate the possibility that a buffer caused this. any ideas?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Your script doesn't exactly match what is expected for an Apache piped log script so what exactly is output is likely undefined. A minimal PHP example is:

#!/usr/local/bin/php

<?php
$stdin = fopen ('php://stdin', 'r');
ob_implicit_flush (true); // Use unbuffered output
while ($line = fgets ($stdin))
{
    print $line;
}
?>

See http://www.sudleyplace.com/pipederrorlogs.html for more details. First get it working so it simply outputs everything it receives and then add features to it as needed.

share|improve this answer
    
i was not a ware that you need to print the input. didnt see that in the official documentation either. but doesnt seem to help. i thought my example was quite minimal, took yours and added the line to write to another file so i can see whether it works. tested from hand in the shell works fine. is my log format defnition fine? –  The Shurrican Jun 8 '11 at 19:12
1  
The print was used in this case as he was forwarding the pipe to another file via ErrorLog "|/path/to/script/script >>/path/to/logfile/logfile". Sending the output to another file like in your case would be fine as well. Your LogFormat looks fine as well. You can test the LogFormat by just outputting to a normal log file and making sure what you want is being output. You can also replace the PHP script with a simple shell script for testing to make sure the piped log is actually working. –  uesp Jun 8 '11 at 20:03
    
i think i messed something up with the places where i defined the logs... thanks for the hint with the unbuffered output and clearifying the stdout issue. now i am a bit more clever tough i am going with another solution i am following the file using tail which is just fine. –  The Shurrican Jun 9 '11 at 0:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.