I've decided I want to rewrite my current blog software in Haskell, and I'm going to blog about it as I go along. I actually started this a few weeks ago, keeping track of everything, but decided it would be much more useful to blog as I go along. I'll post brief reports from my first 5 sessions, lumping some of them together.
Having links that look like
https://lukeplant.me.uk/blog.php?id=1107301655really isn't good for my credibility as a web developer, and just plain sucks anyway
After a heavy load of spamming, my comments file very occasionally gets truncated (I'm storing everything in a flat file database at the moment). I imagine it is to do with PHP aborting part way through a request, when the comments.txt file has just been opened for writing. I've tried to stop this happening, but obviously not successfully. A real database is the answer, which, along with various other improvements I want to make, gives me an opportunity to do a rewrite :-)
I want to learn some Haskell in a real world project,
So, please don't post a comment saying "Why don't you just install WordPress etc?" — I'm doing this for the sake of learning :-)
I'm a typical Yorkshireman — tightfisted as they come, and my web host is very basic. This means that if I'm using Haskell, I'm limited to CGI. My database is also limited to MySQL.
I've got very limited time. My coding will have to be done in sessions up to 90 minutes, usually less. So, this may take a long time, and it may never produce anything. But hopefully I'll learn things in the process.
Haskell Blog Rewrite - Session 1 - 2007-07-05
Hello world in Haskell CGI
Basic performance test on local box and on actual host
Get Apache redirection working if possible
Had to download and install cgi, xhtml and html libraries from Hackage. Thankfully Haskell libraries are now pretty much standardised, and it is easy to install locally rather than mess up your system.
s/NewCGI/CGI in the above tutorial — then it worked.
How do I get apache to actually run the stupid CGI, instead of returning it?! Ah:
<Directory "/my/webdev/folder/cgi-bin"> AddHandler cgi-script .cgi </Directory>
Usual hassles with the fact that I'm wanting Apache to read files within my home directory, which means extended permissions on all the relevant files (and parent folders, but I'd already done that)
40 minutes in: 'Hello, blogosphere' works in local machine. blog.cgi is 1.54 MB.
1h in: found out how to link statically so that it would work on my real host and now it's working. blog.cgi is now 2.2 Mb, which means I'm likely to get a big latency hit the first time it is accessed for a while, but after that it won't really affect its performance.
wajig install siegeto test it. For my live host, I was getting about 22 requests/sec, which is 4 times better than my current blog (PHP) at 5.6 requests/sec. (That sounds pretty bad — but I have made no attempt to optimise my current PHP blog). This lets me know that CGI is practical. CGI may be considered 'retro', especially when you can get 4000 requests/sec using FastCGI but CGI will be good enough for me and I can't use FastCGI anyway. If I do decide to upgrade my host, I should have slashdottable performance.
1h 30 - done for the day, Apache URL rewriting works:
Achieved my basic aims.