[Gambas-user] Embeded HTTP server

Benoît Minisini gambas at ...1...
Thu Sep 27 23:51:11 CEST 2012


Hi,

In revision #5209, I have added an experimental new feature to the 
interpreter, which is an... embedded HTTP server.

At the moment, you can only use it from the command line.

By running the interpreter with the '-H' option, the current project is 
run as a CGI script from an embedded HTTP server.

In other words, provided that your application is a CGI script, running 
it with the '-H' option transforms it into a running local web site.

For example:

$ cd /path/to/my/cgi/script/project
$ GB_HTTPD_PORT=8000 gbx3 -H
...
[Hit ^C to stop it]
$

Note the GB_HTTPD_PORT environmental variable that is needed, otherwise 
the embedded HTTP server will try the port 80, which is reserved to root.

How does it work? "gbx3 -H" will just run the embedded HTTP server, and 
when a request arrives, it will fork and run the Gambas interpreter 
normally. As many initialization have already been done by the HTTP 
server (all components have been loaded), the CGI script should run 
faster than when it is run from a normal HTTP server like Apache.

Another variable is GB_HTTPD_TIMEOUT, which is how many seconds a CGI 
script can run before being killed by the HTTP server.

I made that feature so that we will be able to debug web application 
directly from the IDE. Actually I don't know if this is possible. I 
mean: running a CGI script step by step like a normal program while the 
HTTP server is running and serving other HTTP request from the same CGI 
script!

Anyway, even if it is not possible at the moment, that feature will 
allow to run a Gambas project as a full standalone http server serving a 
complete website.

I hope some of you will find that interesting. :-)

Regards,

-- 
Benoît Minisini




More information about the User mailing list