Websh was originally developed by Netcetera AG, Switzerland and was contributed to the Apache Software Foundation in 2001.
Most recent version is Websh 3.6.0b5 (2009-09-14)
Unfortunately, Apache "discontinued Websh support and development for lack of resources."
Tcl is a good programming language in the sense that it represents program as a list of commands, which is similar with our nature language.
Tcl is also powerful with many "fancy" programming concepts available starting from very learly days.
The idea of using Tcl for web programming is natural. Websh is one of such effort.
Websh can be used in one of below 4 ways:
Although Websh is originally designed for web, I found it's also useful to use it other place.
The key concept here is "command", just like the one in Tool Command Language (Tcl).
A hello world Websh script looks like below. web::command
and web::dispatch
is the two main commands.
web::command hello {
web::put "hello"
}
web::command world {
web::put "world"
}
web::dispatch
Websh is a pure Tcl extension. The build process is similar with
cd src/unix
autoconf
./configure
--with-tclinclude=/usr/include/tcl
--with-httpdinclude=/usr/include/apache2
--enable-threads
make
make test
make apachetest
make install
Make will create three targets: websh3.6., which is the standalone Websh application (dynamically linked to Tcl and libwebsh3.6..so) and libwebsh3.6..so, which is a TEA (Tcl Extension Architecture) compliant shared object that can be dynamically loaded from within Tcl using [load libwebsh3.6..so]. Both provide the Tcl package websh. The third target is mod_websh3.6..so (also dynamically linked to Tcl and libwebsh3.6..so), which is the Websh Apache module.
Websh applications can run in either CGI mode or through mod_websh
.
LoadModule websh_module /path/to/mod_websh.so
<IfModule websh_module>
WebshConfig /path/to/websh.conf
AddHandler websh .wsh
IfModule>
With mod_websh, Tcl interpreter can be reused between each requests.
This feature can give a big boost to web script response time.
set classid [web::interpclasscfg]
web::interpclasscfg $classid maxrequests 100 ;# handle at most 100 request
web::interpclasscfg $classid maxttl 600 ;# live at most 600 seconds
web::interpclasscfg $classid maxidletime 180 ;# idle at most 180 seconds
Since the interpreter can be reused, we have the need of setup at the start once and cleanup at the end.
#----------------------------------------------------#
# web::initializer will execute in listed order #
#----------------------------------------------------#
web::initializer {
web::logdest add user.-debug file -unbuffered /tmp/test.log
web::logfilter add *.-debug
web::log info "initializing interp"
}
#----------------------------------------------------#
# web::finalizer will be executed in reverse order #
#----------------------------------------------------#
web::finalizer {
web::log info "start shutting down interp"
}
web::finalizer {
web::log info "just before shutting down interp"
}
#----------------------------------------------------#
# web::command will be dispatched from web::dispatch #
#----------------------------------------------------#
web::command default {
web::put "hello"
web::putx /path/to/page.html
}
web::dispatch