web programming

1 view
Skip to first unread message

Rod

unread,
Jul 29, 2009, 1:33:35 PM7/29/09
to Bay Area Haskell Users Group
Is anyone looking into using Haskell for cgi programs? This is
something I'm attempting and I was wondering if anyone else wanted to
work together on learning this. Actually I'm new to web development in
general as well as to Haskell, so all this is for experimenting.

baguasquirrel

unread,
Jul 29, 2009, 11:01:41 PM7/29/09
to Bay Area Haskell Users Group
I've never done cgi is, but I was able to do some request handlers
with Happstack... which is tantamount to building your own webserver,
but I figure the webserver was never the part that needed to scale
anyway.

It was easy enough to do request handlers with the code that Happstack
provides (and I dare say fun). Just skip their whole macid thing,
which kind of clunky and difficult. You *do* have to know a thing or
two about the HTTP protocol itself, in order for the apis to make
sense, but since you mentioned cgi I figure you know your way around.

Good luck and happy hacking.

Christopher Abad

unread,
Jul 29, 2009, 11:24:03 PM7/29/09
to baha...@googlegroups.com

Well web cgi programming in haskell like it was in c ala cgi counter.c is pretty straight forward just spew some content-type headers and content and go so I assume you mean some other kinda thing (aka some shake and bake cgi apis?)

On Jul 29, 2009 8:01 PM, "baguasquirrel" <baguas...@gmail.com> wrote:


I've never done cgi is, but I was able to do some request handlers
with Happstack...  which is tantamount to building your own webserver,
but I figure the webserver was never the part that needed to scale
anyway.

It was easy enough to do request handlers with the code that Happstack
provides (and I dare say fun).  Just skip their whole macid thing,
which kind of clunky and difficult.  You *do* have to know a thing or
two about the HTTP protocol itself, in order for the apis to make
sense, but since you mentioned cgi I figure you know your way around.

Good luck and happy hacking.

On Jul 29, 10:33 am, Rod <rli...@gmail.com> wrote: > Is anyone looking into using Haskell for cgi...

Itai Zukerman

unread,
Jul 30, 2009, 7:17:21 PM7/30/09
to baha...@googlegroups.com
> Is anyone looking into using Haskell for cgi programs?

Here's a really short program that tests FastCGI. With apache, speed
was comparable (slightly faster) to a PHP script that did the same
thing. Compile this, put the result in, say, counter.fcgi, configure your web
server to process .fcgi as fastcgi, and you're done.

import Data.IORef
import Text.Printf

import Network.FastCGI

test :: IORef Int -> CGI CGIResult
test counter = do setHeader "Content-type" "text/plain"
n <- liftIO $ readIORef counter
liftIO $ writeIORef counter (n+1)
output $ printf "Hello, world: %10d\n" n

main = do counter <- newIORef 0
runFastCGIConcurrent 4 $ test counter

Reply all
Reply to author
Forward
0 new messages