PI and dc(1)

Thursday, 10. 20. 2005  –  Category: vague

echo '99[lslc+vsslp2*ls/splslk+lc>a]sadk_1*sk10lk^sk0ss2dscsplaxlppq' | dc

As an introduction to C programming and unix, my first tech boss asked me to write a dc(1) clone. I really doubt it could have handled this (somewhere there’s a 3.5″ floppy with my code on, no doubt). I went on to write a lexer with awk(1), the less said about that the better…

rotatelogs

Thursday, 10. 20. 2005  –  Category: todo, web

I’m basically a fan of rotatelogs(1) for Apache logging: no need to gracefully restart, easy filenames to script with, encourages log ageing.

I do however find myself forever doing stuff like

$ ls -tr /a/log/dir | tail
error_log.1129593600
error_log.1129680000
error_log.1129766400 
$ tail -f error_log.1129766400
to diagnose a problem.

What would be cool was if rotatelogs linked, say, error_log.current to the, er, current log. If it used a hard link, you could probably use tail’s -F flag to seemlessly glide over rotations.

Update: I looked at the source; what immediately occurs to me is that both soft and hard linking aren’t particularly portable, and Apache runs on many different platforms. It’s probably more straightforward to do this with a shell script or similar.

PHP, IE and file downloads

Thursday, 10. 20. 2005  –  Category: web

A developer I work with was having problems with some PHP code that generates a spreadsheet for download over https. It all worked swimmingly on Firefox, Safari etc, but not Internet Explorer which would promptly error with a ‘file not found’ dialog box. The Content-Type header was variously ‘application/octet-stream’ and ‘application/vnd.ms-excel’, but neither worked.

PHP defaults to sending nocache headers, and this makes IE aggressively zap any temporary files that arise, even if they’re destined for another app locally.

We fixed this by setting PHP’s cache limiter knob on a per-download basis, although it can be done system-wide also. Here’s the page in the PHP manual.

Whilst investigating this, I encountered the ugly truth about IE’s mime-type handling. Seems fiddly!