Hello!
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?
Thank.
Hello!
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?
Thank.
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 .
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>");
Testing.
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.
Problems:
no tools. You have to write yourself.
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 ..
hosting is not suitable. Need a virtual dedicated server.
It is necessary to correctly implement separate processing of get, post requests.
processing of file download (via post), image upload processing (for captcha for example).
working with headers (sometimes you want to display a header depending on the results, at run time).
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.
If the development environment does not support working in utf-8 encoding, then there will be many to_utf8 () to_ansi ().
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.
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.
Pros:
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.
Get acquainted with the internal structure of the http protocol. Perhaps even with tcp / ip, dns, smtp, pop.
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 ...)
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.)
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.
You can use a C ++ framework such as CppCMS
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 .
Source: https://ru.stackoverflow.com/questions/149380/
All Articles