如何保存CGI应用程序的服务器状态?

发布于 2024-08-20 07:52:51 字数 377 浏览 5 评论 0原文

我有一个 cgi Web 程序(C 语言),可以将不同的错误消息打印到日志文件中。如果程序再次运行并遇到相同的错误,我不希望再次记录相同的错误消息。我正在考虑不同的选择,任何建议都会受到赞赏。谢谢。

-Cookie:打印出 html 部分后无法设置 cookie。
(在头部分之后是可能发生错误的地方。)

-数据库:没有。对于这个问题来说,安装一个的开销太大。

-解析日志文件:许多其他进程正在写入此日志文件。

-html 文件上的隐藏表单输入:看起来很混乱。在同一个 html 页面上有 3 种不同的表单。我如何确保无论提交哪种表单,始终都会提交隐藏字段?但错误之一是无法生成 html,因此不能依赖于此。

谢谢。

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 overhead 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

我不咬妳我踢妳 2024-08-27 07:52:51

另一种选择是在任何可能的地方创建某种形式的临时文件(不确定权限)并在执行任何工作之前读取该文件。也许只是简单地列出错误类型和可选时间?这是假设您希望在程序运行期间保持此行为。实际上,这是没有数据库的数据库解决方案,所以我不确定这有多大帮助。

每当我提到没有数据库的数据库解决方案时,我总是不得不提到SQLite,它是一个基于文件的无服务器 SQL“服务器” 。

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".

无人问我粥可暖 2024-08-27 07:52:51

将构建的页面存储在变量中并在最后输出它将允许您在此之前的任何时间发出标头。

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

在风中等你 2024-08-27 07:52:51

我认为你应该重构你的程序以创建其所有输出,然后将任何 HTML 发送到客户端,这样你就能够事先知道所有现有错误并设置 cookie。

现在,如果由于任何原因这不可行,您应该有一个临时文件来标识 IP 地址和用户代理以及已显示的错误。一个简单的文本文件应该足以快速解析。

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.

难理解 2024-08-27 07:52:51

使用 memcached 可能是在不同会话中保持状态的一种方法。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文