Saw, but did not find the necessary articles. Who has experience, how to make a site in C ++ and what are the pitfalls? Can I work with SQLITE?


Closed due to the fact that it is necessary to reformulate the question so that it was possible to give an objectively correct answer by the participants of Kromster , lexxl , Streletz , user207618, Ivan Pshenitsyn 16 Aug '16 at 18:54 .

The question gives rise to endless debates and discussions based not on knowledge, but on opinions. To get an answer, rephrase your question so that it can be given an unambiguously correct answer, or delete the question altogether. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 2
    site? can the server ?? - Gorets
  • 3
    possible, but why? - Zowie
  • eight
    Is it better for PHP? - VladislavMSK
  • 7
    @ VladislavMSK - java, c #, node.js, ruby, python ...... By the way, why C ++? ASM is better right away, machine code is even better, why is it that “trifles”? By the way, from tz. just stupid site - yes, better in php - Zowie
  • four
    @ VladislavMSK, apparently you don’t own C ++ if you ask such questions. - Viacheslav

3 answers 3

You can but hemorrhoids. You can work with any DBMS. Though your own write.

I can tell only under windows. IIS web server.

Option 1:
easiest via CGI. The output of such std :: cout << "<br> <p> HTML </ p>";

Disadvantages: A separate process is launched for each request, and closes upon completion. This leads to a serious decrease in performance.

Option 2: Use the fastcgi protocol. Here the output will be through a function in ("<br> <p> HTML </ p>");


hello world:

C++ (fastcgi) ~ 12000/сек.(свыше 12000 кидаются исключения из w3wp.exe) php (fastcgi) - 6300/сек. perl (isapi) - 2200/сек. python (isapi) - 15280/сек. (кэширование) python (cgi) - 74/сек. 

150000 cycles with addition and multiplication operations:

 C++ - 5500/сек.(long long) php - 220/сек. в 25 раз perl - 48/сек. в 114 раз python cgi - 34/сек. в 161 раз 

50,000 cycles . counter output i (network load)

 C++ - 950/сек. php - 750/сек. perl - 7/сек. python cgi - 9/сек. 

@nolka Probably 50,000 per second. I had load balancing for multiple servers. And php was launched not as fastcgi, but as cgi. But still the result is indicative.


  1. no tools. You have to write yourself.

  2. not the fact that the finished site will work faster. If the level of the programmer is not very high, then most likely the performance will be much worse than the same site written in a specialized language ..

  3. hosting is not suitable. Need a virtual dedicated server.

  4. It is necessary to correctly implement separate processing of get, post requests.

  5. processing of file download (via post), image upload processing (for captcha for example).

  6. working with headers (sometimes you want to display a header depending on the results, at run time).

  7. handling ajax requests is also different. This should be taken into account both for the entire application (separate exe for ajax processing) and for post get processing via ajax. Again, all server variables come in different ways. And if you don’t know the http protocol well, then the code will have many patches.

  8. If the development environment does not support working in utf-8 encoding, then there will be many to_utf8 () to_ansi ().

  9. Encoding the urldecode () query string from different browsers is different. We'll have to use the curl + normal hex decoding bundle. When ajax request is better to wrap everything in urlencode from javascript. Naturally, if the site has a flash or another language, it will also encode everything in different ways. We'll have to get into the source of these flash and change everything there.

  10. There are no ready-made "scripts" for certain tasks for the server. Everything needs to be developed from scratch.

Basically, writing in C for the web is like writing gui in assembler.


  1. With proper execution, the speed of the program will be very high. (for example, before the cycle of receiving requests, the process collects the required data from the disk, and puts them into memory, where it sorts and indexes). Connection with subd is established before the cycle of receiving requests.

  2. Get acquainted with the internal structure of the http protocol. Perhaps even with tcp / ip, dns, smtp, pop.

  3. With proper execution and configuration of the hosting, the site will not be able to hack. Hackers will have to study its structure. (And not like that: a vulnerability was found in joomla version 1.5.241, all users of this version should download the patch, otherwise hackers can ...)

  4. It all depends on the developer. No new version of the language should lead to problems. (A la in version 2.1507ab, outdated ones have been deleted ... or similar moments are impossible in this language.)

  5. There are no confidential information leaks. CMS (WordPress for example) may contain special instructions for transferring certain information to CIA data analysis centers or become inoperative at a certain moment.

Instructions: Windows. IIS web server. CGI protocol.

 1) Создаешь консольное приложение C++. 2) убираем предварительно скомпилированный заголовок. 3) Запускаем консоль IIS. сайты -> добавить веб сайт. имя: CGI путь: C:\inetpub\CGI ОК 

We go to this site in the console.

 4)Документ по умолчанию: index.wpp 5)Типы mine: .wpp text/html 6)Далее в папке C:\inetpub\CGI создаем пустой файл index.wpp. 

7) In C ++ project we put the lines

 #include <iostream> int main() { std::cout << "\nПривет мир С++ в web!"; return 0; } 

8) Compile. Take the exe file. let's say this is CGI.exe

 кладем в папку C:\inetpub\CGI 

9) then go back to the IIS settings -> sites -> CGI -> handler mapping -> add module mapping.

 путь запроса: *.wpp модуль: cgimodule исполняемый файл: "C:\inetpub\CGI\CGI.exe" имя: главный да. 

10) All now we go on ip which is specified in site bindings. The browser displays a welcome line.

Instructions: Windows. IIS web server. FASTCGI protocol.

 1) Качаем libfcgi2 отсюда http://www.coastrd.com/download вот это: DLL library + headers for C/C++, Delphi, VB & other BASICs 2) Из архива папку С++ кладем в папку include среды разработки. Lib в папку с lib файлами, а dll в папку С:/include/fastcgi test 3) По этой ссылке смотрим как сконфигурировать сам IIS http://www.coastrd.com/cgioniis7 в принципе не отличается от CGI метода, надо только выбрать модуль не cgimodule, а fastcgimodule. 4) Создаем новый проект консольный.(только x32) В него добавляем такие строчки #ifndef _FCGXAPP_H #include <libfcgi2.h> #endif #pragma comment(lib, "libfcgi2.lib") #include <iostream> // функция вывода static inline void v(const std::string & text , FCGX_REQUEST & FCGI) { FCGX_PutStr( text.data(), text.size(), FCGI.pOut); } static inline std::string int_to_string(int integ) { if(integ == 0){ return "0"; } char * buffer = new char [32]; _itoa_s(integ, buffer,32, 10 ); return buffer; } static inline void v(const int & integ , FCGX_REQUEST & FCGI) { std::string global_string = int_to_string(integ); FCGX_PutStr( global_string.data(), global_string.size(), FCGI.pOut); } int main() { // счётчик запросов long long count_fastcgi = 0; FCGX_REQUEST FCGI = { 0 }; FCGX_InitRequest( &FCGI, 0, 0 ); std::string first = "Content-Type: text/html;charset=utf-8\r\nX-Powered-By: C++\r\nAccess-Control-Allow-Origin: *\r\n\r\n"; const char * first_string = first.data(); int size_ = first.size(); //first+="Access-Control-Allow-Origin: *\r\n\r\n"; while( FCGX_Accept_r(&FCGI) == 0 ) { // Вывод заголовков. FCGX_PutStr( first.data(), size_, FCGI.pOut ); // переменные сервера for(int i = 0; i < FCGI.nParam ; i++) { v("<br>" , FCGI); v(FCGI.envp[i] , FCGI); } } // цикл return 0; } 5) После компиляции кладем fastcgi.exe в папку С:/include/fastcgi test Добавляем сопоставление модуля в IIS. Тоже самое как в cgi, только указать не cgimodule, а fastcgimodule. 

If everything worked, we take apache jmeter (which by the way is written on java -> terribly buggy), set the full optimization in the compiler and see how many pages it can process. The main thing is that this jmeter itself does not hang.

  • And what is Yandex and Google written on? It is clear that not on PHP, on Java or what? This is unrealistic, it’s very sluggish - VladislavMSK
  • facepalm .... - KoCaTKo
  • Oh, how much java is in Google, it’s time to know that C ++ is on their back end - vanekk1
  • If you look at Yandex vacancies, you can see that C ++ is also there. - Lucky
  • 3
    Mnogabukoff. Neither asilil, but cool! Plusadynadyn. - gecube

You can use a C ++ framework such as CppCMS

  • Is this something completely new? @pustreg, I read about 5 minutes on your link, and did not understand, CppCMS itself is an http server or what? - avp
  • You know, if you write a site in C ++, then it should have its own engine. Otherwise, what's the point? - manking September
  • 2
    @manking, and all the basic functions of PHP (which means joomla), aren't they written in C? Is it really necessary to refer to them a layer of interpretation? - avp
  • 2
    "You know, if you write a site in C ++, then it should have its own engine." And on what fuel will this engine work? Or is it electric? - alexlz
  • 3
    The simple output of hello world in PHP is 500 pps. on fastcgi C ++ 50000 p / sec. All kernels are 100% clogged. tested 2 years ago on apache jmeter. It is clear that php already parses the incoming request and creates post get arrays, and other moments. But if you competently create only those components that are needed by the site, then for a large company you will get a huge savings on the servers. I think most serious projects, and not only on the web, are written in C / C ++, plus their own engine. - manking

I recommend the library Wt . Templates, sessions, translations into the client's language. Work with DBMS, JSON, AJAX and COMET. Russian documentation is really not enough.

Also recommend crow .

Recently, I developed a javascript template engine and a compiler for json generation modules for lighttpd on pure C: mod_json-dev .

  • Full site will be possible to blind? Interesting, I'll try. - VladislavMSK
  • I myself recently work with it, I write browser games, I am surprised at the breadth of possibilities. Passed several pitfalls, there will be problems - ask. I recommend to immediately install the latest version, which is obsolete in the Debian. - sercxjo
  • one
    in addition, there are crow / http2 frameworks that support routing and middlevary interfaces. There are lots of libraries to work with sql (I prefer sqlp11) - strangeqargo
  • 2
    @strangeqargo where were you a couple of months ago :) when I decided to make my template engine + json generator on pure C. - sercxjo
  • one
    @ VladislavMSK on wt, sure you can. on crow / cpphttp2 + rapidJSON (the fastest now, it seems) can at least be done, for example, api for the frontend (I am having fun with it). Crow cannot by default distribute static, but middleware is written very quickly for this (did, then I’ll post it in githabiki if need be) - strangeqargo