Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » SCGI Class
SCGI Class [message #28120] Tue, 17 August 2010 16:35 Go to previous message
jeremy_c is currently offline  jeremy_c
Messages: 175
Registered: August 2007
Location: Ohio, USA
Experienced Member
I have created a SCGI class. SCGI is a more simple FastCGI interface. It allows the application to persist between connections, thus respond very quick unlike a CGI program that has to be loaded, initialized, executed and closed for each request.

This really comes in handy when there are expensive start up costs such as a database connection.

An example application:


#include <SCGI/SCGI.h>

class HelloWebApp : public ScgiServer {
public:
  HelloWebApp() : ScgiServer(8787) 
  {
    WhenRequest = HandleRequest;
  }

  void HandleRequest()
  {
    clientSocket.Write("Content-Type: text/plain\r\n\r\n");
    clientSocket.Write(Format("Hello, %s!", query["NAME"]));
  }
};

CONSOLE_APP_MAIN
{
  HelloWebApp app;
  app.Run();
}


There are other callbacks such as WhenAccepted, WhenClosed. "query" is public and is an instance of HttpQuery that is automatically populated. "map" is a VectorMap<String,String> that is also automatically populated with the server variables that are passed such as REQUEST_URI, SERVER_NAME, etc...

On my NetBook (1.6ghz Atom) the above SCGI app runs ~1200 requests a second. A static hello.txt file is ~1900 requests a second.

I still have a few loose ends to wrap up (post form data, some more general testing) but wondering if anyone else would find this useful and how to share it?

Oh... most web servers (Apache included) have a "mod_scgi" to interface with this type of application. The applications need not reside on the same computer as the web server, thus they can be distributed and offer load balancing. Advanced servers like Apache can do load balancing themselves internally knowing which SCGI app is in use and which one is not.

For anyone who wants to know more about the SCGI protocol: http://python.ca/scgi/protocol.txt

Jeremy

[Updated on: Tue, 17 August 2010 16:37]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How should we deal with SQL column names in conflict with SQL standard keywords
Next Topic: What's up with Google subversion mirror?
Goto Forum:
  


Current Time: Sat Apr 20 02:20:43 CEST 2024

Total time taken to generate the page: 0.07335 seconds