开发者

How to save server state of CGI application?

I have a cgi web program (in C) that prints out different error messages to a log file. If the program is run again and runs into he same error, I do not want the same error message to log again. I'm looking at different options and any advice is appreciated. Thanks.

-Cookie: unable to set cookie after the html <head> section has been printed out.

(After the head section is where any errors would occur.)

-Database: Do not have one. Too much overh开发者_Python百科ead for this issue to install one.

-Parse log file: Many other processes are writing to this log file.

-Hidden form inputs on html file: Seems messy. Have 3 different forms on the same html page. How do am I sure the hidden fields are always submitted regardless of which form is submitted? But one of the errors is when the html can not be produced, so can not depend on this.

Thanks.


The other option is to create some form of temporary file wherever you are able (not sure about permissions) and read that pre doing any work. Simply list the error types and optionally times in there, perhaps? This is assuming you want to persist this behaviour across runs of your program. This is the database solution without the database, really, so I'm not sure how helpful that is.

Whenever I mention database solutions without databases I always have to mention SQLite which is a file based serverless SQL "server".


Storing the built page in a variable and outputting it at the end will allow you to emit a header any time before then.


I think you should refactor your program to create all its output previously to sending any HTML to the client, that way you'll be able to know beforehand all existing errors and set a cookie.

Now, if this is not viable for any reason you should have a temporary file identifying IP address and user agent and errors already shown. A simple text file should be quick enough to parse.


Using memcached might be a way to keep states throughout different sessions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜