Home  /  RSS  /  RSS Comments  /  Enter

Components of CppCMS

12/30/07, by artyom ; Posted in: Progress, Templates, FastCGI, Framework, Berkeley DB; 3 comments

There are several important components that CppCMS implements:

  1. FastCGI Application Framework
  2. Easy Berkeley DB -- Simple API to BDB
  3. Templates System
  4. Text Tools -- text to html conversion tools
  5. Nice URLs support

I'll describe there all these in details there

FastCGI Framework

What is FastCGI? It is an independent protocol that describes the connection between a webs server and application. Most of popular web servers (Apache, IIS, Lighttpd) implement it and allow any FastCGI web application to work together.

Not going deep to the details, the main idea is creating a persistent process -- a FastCGI application that receives requests from the web server and returns as output a ready web pages. Persistent process allows effective in memory caching of all required data, effective managing of resources and much more. There is a good article "Understanding FastCGI Application Performance" that describes the major advantages of this architecture.

There are good and stable libraries that implement this protocol, however they give quite basic functionality -- like accept the requests, get inputs, return them. No forms processing, no threads/process control, not url encoding or decoding at all. Thus, there is a lot of work to do in order to make a good FastCGI application. This what CppCMS does for the developer.

CppCMS FastCGI framework does following:

  1. Process/Thread control -- prepare a thread pool of several working threads, manage incoming requests and queue them. Receive signals and shot the application safely down.
  2. Connection with CgiCC library -- the library that makes working with HTTP inputs/outputs easy. It implements access to forms, cookies, prepares set of HTTP headers and does huge part of all the stuff that C++ web developer need.
  3. Defines global configuration files that allows easy change of all required parameters like, threads number, sockets, buffers or any other configuration parameters user needs.
  4. Performs gzip compression of prepared pages (in case web server do not support them -- like lighttpd).

Easy Berkeley DB API

Oracle Berkeley DB is one of the fastest databases available on the market. It has powerful in memory cache support, support of transactions and replication over the network.

However it has complicated and powerful API that is not "very developers friendly". It takes lots of time to learn this API and start using it efficiently. Thus, CppCMS introduced simple C++ templates based library that makes Berkely DB access easy and friendly.

The work with it becomes as simple as work with STL containers. For example, this code:

Posts::date_c cursor(posts->date);
for(n=0,cursor.end();n<10 && cursor;cursor.next(),n++){
  post_t post=cursor;
  // Do something
}

reads 10 latest posts from database. This allows comfortable access to fast DB from C++.

Templates System

It is one of the most important parts of any web development framework. It allows separation of the HTML design from the actual code.

The templates system consists of 3 parts:

  1. Templates compilers -- the tool that parses the templates and converts them to internal format that can be easily processed by the code.
  2. Content Container -- the connector between the C++ data and the template content. It is actually a container that C++ code fills with data that can be rendered to output.
  3. Renderer -- the engine that takes the content and the templates and creates an output.

For example, this is a typical part of template code:

<% if def username %>
    <h1>Hello, <% username %>!</h1>
<% else %>
    <h1>Hello, Visitor!</h1>
<% end %>

You can find much more examples here.

Text Tools

As we know, one of the major parts of any CMS is text processing. Thus, CppCMS introduces several tools to do this job.

  1. Text to HTML conversion -- convert all special symbols and text to correct xhtml output.
  2. Markdown to HTML -- the tool that allows conversion of simple subset of markdown to HTML.

This blog uses this tool wring these articles.

Nice URLs support

As you can see the URLs in this blog are very simple. CppCMS implements a simple URL to code mapping that allows easy management of nice urls.

The URLs are defined by regular expressions and the callback function that is called on input event.

For example:

url.add("^/post/(\d+)$",boost::bind(&Blog::post,this,_1));

I connect member function "post" of class "Blog" to the url that defines articles in this blog. This functionality can be easily implemented thanks to boost libraries.

Whats Next?

There are still many things to do: 1. Implement page level cache system 2. Improve Berkeley DB support, 3. Improve text tools to support full markdown and not only the subset. 4. Debug and Test... 5. Create stable API and write documentation

And much more... But it is only beginning.

Comments

Ikipou, at 1/2/08, 5:34 PM

The whole project seems really interesting. Do you have any plan to deal with update (do we have to restart the server to add a component?). What append if we have a division by zero, or a segmentation fault in the code of a page? Does it cancel all the other request and restart the server?

For the "whats next", I propose to add "internationalisation capabilities for the templates". :)

artyom, at 1/2/08, 8:32 PM

Do you have any plan to deal with update (do we have to restart the server to add a component?)

It depends on your setup, if you run CMS as independent FastCGI service so you need to restart your service only, otherwise restart entry server, unless it supports programs restart.

What append if we have a division by zero, or a segmentation fault in the code of a page?

CppCMS supports two variants of work -- multithreaded and mutliprocess. If you had some kind of segmentation fault, the process will die, but most of servers already have capabilities of restarting the dead service or restart them on their own. You can also write your own "health control". It should be quite a simple bash script.

Anyway, a death of FastCGI application do not cause a death of the server. So it is up to the developer -- write better code or prepare to better recovery.

I propose to add "internationalisation capabilities for the templates". :)

Actually there is absolutly no problems to use any other language in templates. You just have to rewrite the language specific content of them. And it is enough. I can just translate the template to Hebrew and add several RTL tags and fixes in order to make this blog working in Hebrew.

In future I think to add something more generic based on gettext.

Anyway, there is still many things to do.

Thanks

Tom Maheso, at 6/1/17, 10:09 AM

Hi,

We would like to use CppCMS together with apache2 on Debian 9 (Stretch). We would also like to have an independent start of our application as it has a lot of other things involved.

Issue: Debian 9 does not have libapache2-mod-fastcgi, instead is has libapache2-mod-fcgid. The fcgid module does not support independent start of an external application. Do you guys perhaps have a configuration for using fcgid which would allow us to start our application independently?

Current Work around used: We resorted to taking the fastcgi module meant for Debian 8 and installed it on Debian 9. By doing this, we could then follow the setup procedure on this website. Though we used TCP/IP sockets and not Unix ones. Are there any shortfalls to this setup?

We would greatly appreciate your response.

Add Comment:

 
 the email would not displayed
 

You can write your messages using Markdown syntax.

You must enable JavaScript in order to post comments.

Pages

Categories