简体   繁体   English

保持CGI应用程序始终在C ++中运行

[英]Keep cgi applications always running in c++

I have written a CGI application and it is run by Apache server, waiting for requests to process. 我已经编写了一个CGI应用程序,它由Apache服务器运行,等待请求处理。 The fact is that after receiving each request, Apache runs the application, processes the requests and replies accordingly. 事实是,在收到每个请求之后,Apache运行应用程序,处理请求并相应地进行回复。 It has some drawbacks in terms of performance since by receiving each request, it has to load all the necessary requirements and initialization. 它在性能方面有一些缺点,因为通过接收每个请求,它必须加载所有必要的要求和初始化。 Another problem is that in the application, I have to keep track of some information for the ACK that the client will be sending later. 另一个问题是,在应用程序中,我必须跟踪一些有关客户端稍后将发送的ACK的信息。 How can I run the application once, get it always wait to serve the requests? 如何运行应用程序一次,使其始终等待服务请求?

It sounds like you want to use mod_fastcgi for Apache. 听起来您想对Apache使用mod_fastcgi From the web site: 从网站:

This 3rd party module provides support for the FastCGI protocol. 该第三方模块提供对FastCGI协议的支持。 FastCGI is a language independent, scalable, open extension to CGI that provides high performance and persistence without the limitations of server specific APIs. FastCGI是CGI的一种独立于语言的可扩展开放性扩展,可提供高性能和持久性,而不受服务器特定API的限制。 ... FastCGI applications are fast because they're persistent. ... FastCGI应用程序之所以快速,是因为它们具有持久性。 There is no per-request startup and initialization overhead. 没有每个请求的启动和初始化开销。 This makes possible the development of applications which would otherwise be impractical within the CGI paradigm (eg a huge Perl script, or an application which requires a connection to one or more databases). 这使得开发可能在CGI范式中不可行的应用程序成为可能(例如,巨大的Perl脚本或需要连接到一个或多个数据库的应用程序)。

If I am understanding your question correctly you would basically be covered by a finite-state machine. 如果我正确地理解了您的问题,那么您基本上将被一台有限状态机所覆盖。 This would allow you to have a "waiting" state, an "action" state, and so on. 这将使您具有“等待”状态,“动作”状态,等等。 Using this would allow you to make a request and act only when the request has been fulfilled. 使用此选项,您可以发出请求,并且仅在满足请求后才采取行动。 A great site for a more in-depth understanding would be "http://www.drdobbs.com/cpp/state-machine-design-in-c/184401236" 一个更深入了解的好网站是“ http://www.drdobbs.com/cpp/state-machine-design-in-c/184401236”

Or you could use promises. 或者您可以使用诺言。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM