Date: Mon, 15 Dec 2008 18:11:18 +0200
From: Mindaugas Kavaliauskas <dbtopas@dbtopas.lt>
To: "Harbour Project Main Developer List." <harbour@harbour-project.org>
Subject: [Harbour] mod_harbour vs apache.prg

Hi,


I've tried to use gtcgi some time ago. For testing only, not for real 
applications. "HelloWorld" .cgi works ok, a large 300 .prg lines cgi 
script also work ok, but I do not like the idea of writing a large web 
database application.
Every time you click mouse on the client, server should load Harbour's 
executable, this executable "links" global symbol table and do a lot lot 
lot more initialization jobs. Then .prg script opens the database 
tables, positions the record to required position and prints:

IF DBSEEK(FIELD->USERNAME, .F.) .AND. ;
    FIELD->PASSWORD == _POST["password"]
   QOUT(FIELD->NAME + " logged in successfully.")
ELSE;  QOUT("You've failed.")
ENDIF

I know computers are fast, but I still do not want to make them do all 
this huge job, when only 5 lines are required. A solution could be 
apache module for Harbour. It can not only execute .prg or .hrb code, 
but also "cache" open workareas, to avoid reopening of .dbf files on 
each request, just like php caches mysql connections (persistent 
connections). But apache module and all these extensions are not planed 
in 1.1 and perhaps not in 1.2.

Let's try to solve problem the opposite way, not port Harbour to apache, 
but port apache to Harbour. Writing http server in Harbour is not a big 
problem. Yes, I know people are working on it for years, but 
"HelloWorld" http server I've wrote in 2 hours (73 lines of .prg code), 
and "real" server in 2 days (490 lines of .prg code).

I have not implemented any Model-View-Control pattern yet, so, I do not 
have Ruby on Rails, but I can implement sessions, post method support in 
a few hours and I'll have something similar to plain php.

Anyone interested can download http://www.dbtopas.lt/hrb/uhttpd.zip
   socket.c - alternative lightweight socket library, I do not like
              hbinet.c a lot. If you want to compile it for Linux,
              you'll need to adjust includes, but code should be
              portable;
   uhttpd1.prg - HelloWorld http server ("u" stands for micro);
   uhttpd2.prg - fully functional http server, enjoy apache compatible
                 server access log :)


Best regards,
Mindaugas


P.S. actually, I was trying to make myself familiar with threads and 
started from tests/mt/mttest07.prg and jobs queue, but the only thread I 
could imagine was http server thread.
BTW, I wanted to make worker threads count dynamic, i.e., create more 
threads if job queue becomes long. How can I find notification queue 
length of Harbour's mutex?
