More CGI Stuff
Yennie at aol.com
Yennie at aol.com
Fri Aug 30 12:15:00 EDT 2002
> Can this be done by having MC running in the background *prior* to the
> cgi being called by the server - not sure how the os associated the
> script with the engine.... or whether it creates another process....
> would like to though:)
>
Unfortunately, no- the server will spawn a new cgi process for each request.
I have found a couple options, however:
1). Run a simple server which takes request from cgi scripts (over sockets),
and supplies the persistent data.
2) Run a pool of servers, all listening on their own port, and then still
utilize 1).
I did cook up something fun to play with. I stuck this in a script "httpd"
and call "./httpd 8080 10" from the terminal. What I get: 10 processes
listening on ports 8080-8089.
This is somewhat like apache's behavior: a bunch of child processes handle
requests. Problem is, Apache uses fork() and select(), so it manages to get
all of the processes listening on the *same* port. I can't see how that is
possible with Metacard.
#!mc
global thisPort, myID, isLastChild
on startup
put $1 into thisPort
put $2 into numChildren
put $3 into myID
put $4 into isLastChild
if (myID is empty) then put 0 into myID
accept connections on port thisPort with message "newConnect"
repeat with pID=1 to numChildren-1
open process ($0&&($1+pID)&&"0"&&(pID)&&(pID = (numChildren - 1)))
end repeat
end startup
on newConnect s
read from socket s until empty
put "HTTP/1.0 200 OK WebCF"&crLF into r
put "Content-Type: text/plain"&crLF after r
put "Content-Length: "&length(myID)&crLF&crLF after r
put myID after r
write r to socket s
end newConnect
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.runrev.com/pipermail/metacard/attachments/20020830/599d8837/attachment.htm
More information about the metacard
mailing list