I’m writing a program in C++ that will run all the time in the background to do different tasks – a deamon.
Apart from it’s usual tasks a web application should communicate with it (AJAX requests in doing a COMET pattern = lots of open but sleeping connections).
So the question is: how should I connect it to the web server (apache and lighttpd are relevant)?
Of what I’ve read FastCGI would be very interesting for that task, but all references I’ve read were talking about the web server starting the FastCGI application when necessary. This wouldn’t work here as the deamon would already be running…
I’ve also read that the web server would talk via socets with the FastCGI application – so that could be an entry point for me, the deamon would “only” need to talk to such a socket.
But are there good libraries available for that?
Looking at the features of http://cppcms.com/wikipp/en/page/main it looks very interesting for me – but could that work in my case? And could it be stripped down – offering even a SQL connection is far too heavy for my case…
So what advice can you give me?
PS: Performance wise I recon a single threaded but asynchronous implementation would work for the deamon <-> web server glue.
FastCGI is the standard protocol to communicate with the web server. All mentioned web servers can communicate with the remote deamon application via fastcgi.
http://cppcms.com/wikipp/en/page/cppcms_1x_tut_web_server_config
Also if you are looking for Comet support, that what CppCMS provides you natively:
http://blog.cppcms.com/post/107
CppCMS library is very small also it allows to reduce its size:
http://cppcms.com/wikipp/en/page/cppcms_1x_build#Build.Options
also SQL connectivity CppDB is independent part.
It is one of the standard CppCMS run mode – running asynchronous web applications.
Update:
Indeed some web servers start the fast cgi applications but:
Apache:
mod_fascgiallows both to start FastCGI application or connect to independent onemod_scgiconnects to independent application – does not start application.mod_fcgidalways starts application – does not suite youAlso as general note, apache does not suit a pattern of working with many idle connections as it uses thread (or even process depending mpm) per connection.
Nginx – does not start applications at all, however for fastcgi currently not the best for comet streaming because of buffering, so SCGI would be better with nginx (assuming you are using latest nginx version)
Small note: SCGI is a protocol that is very similar to FastCGI but significantly simpler.