Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i have a piped logging program like this:


$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);

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
up vote 3 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:


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

See 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
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


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.