CGI Hung Process Help!
Sivakatirswami
katir at hindu.org
Sat May 5 18:09:09 EDT 2007
I have some ancient CGI's that must be nearly 10 years old and
began when I was running metacard on the web server...
Some of these are hanging, not all the time, but just sometimes
and appear as a "run away process" if you check "top" on the web server.
if I get 8 or ten of these, the server load approaches 10 and response times
for httpd start to slow down.
I'm having to manually go in and kill these every other day.
Recent CGI's which are we doing as stacks are not causing this problem.
On the other hand this particular one is a very high traffic form on our
web site.
I don't think were are experiencing and DOS attacks as such, though form
spam
bots used to fill this form out heavily until we put the "check for human"
visual clue (very simple version, not rotated and easily discernible
but it works) that must now be entered, which stopped the bots from
actually getting thru (note the exit top to on the first data verify test)
Andre and I suspect possibly this email segment
# now send invitation triggers to HPI list server
put "/usr/sbin/sendmail -t" into mprocess
open process mprocess for write
write "From:" && tDataIn ["email"] & cr to process mprocess
write "To:" && "hpi_list-on at hindu.org" & cr to process mprocess
write "Subject:" && "Subscribe" & cr & cr to process mprocess
close process mprocess
# wait until the openprocesses is empty
We commented the wait (something I got
from Scott Raney in days of yore... wish he were here~!)
but that did not help...
Any one have any clues on what could cause
this CGI to leave a hung running instance of Rev on the
web server?
what would happen if someone attempted to dump a super
long test chunk into the comments field?
Thanks
Sivakatirswami
PS.
We are using 2.6.1 for Linux and praying to the IT gods
of Edinburgh for a new web server ready linux engine
that will run on our Fedora Core II web box.
#!/usr/local/bin/revolution
on startup
## read in data and split into array
if $REQUEST_METHOD is "POST" then
put "" into PostIn
repeat until length(PostIn) >= $CONTENT_LENGTH
read from stdin until ""
put it after PostIn
end repeat
put urlDecode (PostIn) into tDataIn
split tDataIn by "&" and "="
put keys(tDataIn) into tFields
set the casesensitive to false
## human check first:
if tDataIn["14_CheckForHuman"] <> "Karma" then
put failHumanCheck() into tResponse
put "Content-Type: text/html" & cr
put "Content-Length:" && the length of tResponse & cr & cr
put tResponse
exit to top
end if
## Now check for missing fields
repeat for each line x in tFields
if (x is not among the items of
"5_add2,9_foreign_state,10_Zip,12_Phone,13_Comments" ) then
if tDataIn[x] is empty then put x & "<br>" after missing_fields
end if
end repeat
if missing_fields is not empty then
sendUserFeedback (missing_fields)
exit startup
end if
# test email address is correct
put isEmail(tDataIn ["email"] ) into emailCheck
switch emailCheck
case "False"
put badEmail() into tResponse
break
case "True"
# save data to file on server, pipe delimited, one record per line
put "|" & the date &"|" into tSubmit
sort lines of tFields numeric
repeat for each line x in tFields
put (tDataIn[x] & "|") after tSubmit
end repeat
put numToChar(166) after tSubmit
put tSubmit after url "file:../formdata/guestbook.dat"
# load response template and insert name
# and country specific response.
put tDataIn["2_First"] & " " & tDataIn["3_Last"] into vName
put CountryResponseChunk(tDataIn["11_Country"]) into tCountryChunk
put url "file:../httpdocs/info/gstbk_responses/gstbk_thankyou.html" into
tResponse
replace "###NAME###" with vName in tResponse
replace "###CountrySpecificResponse###" with tCountryChunk in tResponse
end switch
put "Content-Type: text/html" & cr
put "Content-Length:" && the length of tResponse & cr & cr
put tResponse
# now send invitations triggers to HPI and Gurudeva list serve
put "/usr/sbin/sendmail -t" into mprocess
open process mprocess for write
write "From:" && tDataIn ["email"] & cr to process mprocess
write "To:" && "hpi_list-on at hindu.org" & cr to process mprocess
write "Subject:" && "Subscribe" & cr & cr to process mprocess
close process mprocess
# wait until the openprocesses is empty
end if
end startup
# end of cgi, subroutines and functions follow
on sendUserFeedback missing_fields
put "Sorry, please go back and fill in the following required fields:"
& "<p>" & missing_fields into tResponse
put "Content-Type: text/html" & cr
put "Content-Length:" && the length of tResponse & cr & cr
put tResponse
end sendUserFeedback
function isEmail what
return
matchText(what,"^[A-z0-9_\-\.]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]$")
end isEmail
function badEmail
put "<html><head><Title>There is a problem with your email address!"\
& "</TITLE></HEAD><CENTER><BODY BGCOLOR=#ffffff> <FONT
color=FF0000><h3>Sorry,"\
& "there was something wrong in the way you entered your email. <br>"\
& "Please go back and enter it again. Thank
you.</H3></FONT></CENTER></BODY></HTML>" into fixYourEmail
return fixYourEmail
end badEmail
function failHumanCheck
put "<html><head><Title>Human Check Failed"\
& "</TITLE></HEAD><CENTER><BODY BGCOLOR=#ffffff> <FONT
color=FF0000><h3>Sorry, "\
& "robots not allowed <br>"\
& "You must enter the word on the screen and then
submit.</H3></FONT></CENTER></BODY></HTML>" into enterHumanCheck
return enterHumanCheck
end failHumanCheck
function CountryResponseChunk tCountry
replace " " with "_" in tCountry
put ("../httpdocs/info/gstbk_responses/" & tCountry & ".html") into
tResponsePath
if (there is a file tResponsePath) then
put url ("file:" & tResponsePath) into tCountryChunk
return tCountryChunk
else
put url
("file:../httpdocs/info/gstbk_responses/all_other_countries.html") into
tCountryChunk
return tCountryChunk
end if
end CountryResponseChunk
More information about the use-livecode
mailing list