1

Sorry for my lack of knowledge related to this question but: if I want to create a C application that exposes a REST API layer using Apache as web server there are 2 options (at least these 2 I have found googling)

  • using CGI .

  • implement an Apache extension i.e hello_world.so and then load in the Apache configuration

What is the main difference between them in terms of process created, overhead, lag etc?

Thanks.

Community
  • 1
  • 1
d3javu999
  • 323
  • 1
  • 8

2 Answers2

1

Using CGI, one runs the application in a separate process.

Using Apache extensions, the application is a loaded module of Apache, and can run in the same process as Apache.

For performance, you likely want it in the same process; however, if you have a coding error it will bring Apache down.

For stability, you likely want it in a different process; however, the costs associated with starting and stopping the processes will be permanent overhead in your request processing, and that will limit the number of connections you can maintain and service.

There is a compromise, but it shouldn't be seen as the best of both worlds. FastCGI works by reusing the CGI process that Apache uses. However, it is still slower than an Apache module, and incurs more overhead, but that overhead is generally less than traditional CGI.

Edwin Buck
  • 69,361
  • 7
  • 100
  • 138
1

You could consider writing some FastCGI application, and configure your Apache server to speak FastCGI with it. Then you won't (in contrast to old CGI) start a process for every HTTP request, and your application would serve several HTTP requests (transformed into FastCGI requests by Apache) and may keep some state between them.

You could even use some HTTP server library, like libonion, inside your application (which then becomes some specialized HTTP server). You then don't even need any Apache server (or you could configure your Apache server to forward some HTTP requests to your application).

You certainly need to understand more the HTTP protocol itself and its requests and replies header fields, and HTTP cookies.

BTW, any Apache extension is specific to Apache (won't work with most other HTTP servers), and perhaps to its version.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547