Reputation: 531
I have written a CGI application and it is run by Apache server, waiting for requests to process. The fact is that after receiving each request, Apache runs the application, processes the requests and replies accordingly. 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. How can I run the application once, get it always wait to serve the requests?
Upvotes: 2
Views: 440
Reputation: 121
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"
Or you could use promises.
Upvotes: 0
Reputation: 70392
It sounds like you want to use mod_fastcgi
for Apache. From the web site:
This 3rd party module provides support for the FastCGI protocol. FastCGI is a language independent, scalable, open extension to CGI that provides high performance and persistence without the limitations of server specific APIs. ... FastCGI applications are fast because they're persistent. 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 (e.g. a huge Perl script, or an application which requires a connection to one or more databases).
Upvotes: 1