slow CGI with open socket

Scott Raney raney at metacard.com
Mon Mar 25 12:30:01 EST 2002


LiangTyan Fui <mlist at afteroffice.com> wrote:

> OK list, here is a problem that I have no answer for the last 2
> days.  I am working on Linux based MetaCard CGI, everything went
> smoothly by far except when I was trying to use "open socket".  When
> a "open socket" command is used, the script took unreadably longer
> time to exit, even without any problem. I've tried to run the script
> under Apache as CGI and directly from the shell, both yield the same
> result.

> You may cut the following script and save it as your .mt file in
> your server to tryout. Remember to modify the first line of the
> script to your real MC runtime engine.

> Thanks.

> ------------ script start ---------
> #!/home/mc/mc
> 
> on startup
>   # any local http server will do, if you have one
>   put "www.yahoo.com:80" into thesock
>   
>   put the long ticks into startTicks
>   open socket thesock
>   close socket thesock
>   put the long ticks - startTicks into ticksTaken
>   
>   put "Content-Type: text/plain"& crlf & crlf
>   put "Ticks taken for this CGI to excute: "& ticksTaken
> end startup
> ------------ script end ---------

Works fine here, I get about 0.391975 (though why one would use the
long ticks instead of the milliseconds, I don't know ;-)

Note that the CGI itself could take up to 10 seconds to exit because
it waits for that socket to time out, though (.mt scripts won't exit
while there are open sockets because it doesn't know if maybe some new
input is pending for them, and immediately opening and closing a
socket could cause it to assume that there is something like that
that's supposed to happen).  You won't have this problem if you do
some actual work that causes the server to close its socket followed
by your app reading until eof on it.  You could also force this clean
up to occur by calling the openSockets.
  Regards,
    Scott

********************************************************
Scott Raney  raney at metacard.com  http://www.metacard.com
MetaCard: You know, there's an easier way to do that...





More information about the metacard mailing list