Subject: Short reads in CGI applications: THE SCOTT'S "CHAMPAGNE" WAY !
Pierre Sahores
psahores at easynet.fr
Fri Dec 20 09:33:00 EST 2002
> * From: Scott Raney
> * Subject: Short reads in CGI applications: A solution
> * Date: Thu, 24 Oct 2002 20:04:55 -0700
>
> We've recently received several reports of short reads from stdin in
> CGI applications but have never been able to reproduce or understand
> this until our own (recently upgraded) server started to show the
> problem. Not sure if it's a newer version of the HTTP server software
> or faster hardware or what, but sometimes "read from stdin until
> empty" doesn't get all the data it should. Sometimes it doesn't get
> anything at all.
>
> Now "read .. until empty" was never a good idea, merely a quick and
> dirty way to read whatever should be incoming in the first bufferfull
> from the HTTP server. Unfortunately the easy workaround, "read from
> stdin for $CONTENT_LENGTH" also doesn't work if the process on the
> other end of stdin doesn't keep up. So what you have to do instead is
> something like:
> put empty into buffer # this is where your data will end up
> repeat until length(buffer) >= $CONTENT_LENGTH
> read from stdin until empty
> put it after buffer
> end repeat
>
> We'll look into supporting a simpler way to do this for 2.5 (not sure
> whether to fix it so "read .. for $CONTENT_LENGTH" works, or to
> support "read .. until eof" on pipes), but in the mean time something
> like the above should solve the problem.
> Regards,
> Scott
>
> ********************************************************
> Scott Raney raney at metacard.com http://www.metacard.com
> MetaCard: You know, there's an easier way to do that...
>
Allo Scott,
It works !, as fine, and even best in pure cgi-mode, as the php-based
workaround script i used until today because i never got the secure and
expected results in using the below kind of code :
> | #!/usr/local/bin/mc
> | on start up
> | if $REQUEST_METHOD is "POST" then
> | read from stdin until empty
> | put it into buffer
> | put "Content-Type: text/plain" & cr
> | put "Content-Length:" && the length of buffer & cr & cr
> | put buffer
> | end startup
I was just searching for an mc way to build a cgi-script based front-end
to postgresql, to explain in the simplest way (without needing to set up
an mc web apps deamon) on how to to build and send SQL
statements/queries to pg, directly from within mc. Thanks, thanks,
thanks : the onest problem i had in using mc for years has gone away
:-)))
--
Best Regards, Pierre Sahores
Inspection académique de Seine-Saint-Denis.
Applications et bases de données WEB et VPN
Qualifier et produire l'avantage compétitif
More information about the metacard
mailing list