Making SSH client use line buffered stream

So I found out about stdbuf. To get it:

# apt-get install coreutils

If you want your ssh client to use line-buffered streams use -t -t.

So I ended up with:

# su -c "stdbuf -oL ssh -t -t /usr/bin/tail -f /var/input.log | stdbuf -oL tr -c '\\11\\12\\15\\40-\\176" myuser \
  | tee -a /tmp/input.log \
  | grep --line-buffered -v "...ignore..." \
  >> /tmp/output.log

Holy command-line Batman!

HTTPS+SSLVerifyClient require in <Directory>+big POST = Apache error

I was configuring MediaWiki to allow uploads and was getting an error in the browser about the POST data being too large (“does not allow request data with POST requests, or the amount of data provided in the request exceeds the capacity limit.”). I had a look in the Apache error log and found:

[Thu Feb 23 16:12:45 2012] [error] [client] request body exceeds m
aximum size (131072) for SSL buffer, referer:
[Thu Feb 23 16:12:45 2012] [error] [client] could not buffer messa
ge body to allow SSL renegotiation to proceed, referer:

So I did some research. I found this document, File upload size which suggested editing /etc/php5/apache2/php.ini which I did:

upload_max_filesize = 20M
post_max_size = 80M

That didn’t fix the problem though. I found Request entity too large which suggested checking my setting for LimitRequestBody, but that wasn’t the problem either.

Eventually I found Bug 491763 – HTTPS+SSLVerifyClient require in <Directory>+big POST = Apache error which suggested I needed to apply the SSLRenegBufferSize directive which I did like this:

  <Location /morpheus>
    SSLVerifyClient require
    SSLVerifyDepth 1
    SSLRenegBufferSize 20971520

And then after restarting Apache the problem was solved.

Using PHP output buffering to read a file

There’s a function in PHP called readfile which will read a file and send its contents to stdout. That can be handy, but it’s not much good to you if you want to read the content of the file into a string.

There’s a neat trick using PHP’s output buffering that enables you to read the content of a file into a string without printing anything on stdout, and it goes like this:

  // start an output buffer
  // print the file to the output buffer
  readfile( $file_path );
  // get the contents of the output buffer
  $content = ob_get_contents();
  // cancel the output buffer