{"id":213785,"date":"2021-03-29T15:00:07","date_gmt":"2021-03-29T12:00:07","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/what-is-the-common-gateway-interface-cgi-cloudsavvy-it\/"},"modified":"2021-03-29T15:00:07","modified_gmt":"2021-03-29T12:00:07","slug":"what-is-the-common-gateway-interface-cgi-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/what-is-the-common-gateway-interface-cgi-cloudsavvy-it\/","title":{"rendered":"#What Is The Common Gateway Interface (CGI)? \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a261ee5a6f45\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a261ee5a6f45\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/what-is-the-common-gateway-interface-cgi-cloudsavvy-it\/#Standardising_HTTP_Servers\" >Standardising HTTP Servers<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/what-is-the-common-gateway-interface-cgi-cloudsavvy-it\/#Information_Exchanged_Via_CGI\" >Information Exchanged Via CGI<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/what-is-the-common-gateway-interface-cgi-cloudsavvy-it\/#Wheres_CGI_Today\" >Where\u2019s CGI Today?<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#What Is The Common Gateway Interface (CGI)? \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-10387\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/03\/88aaea59.jpg?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Photo of Ethernet cables in a server\" width=\"1600\" height=\"900\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>The Common Gateway Interface (CGI) is a standard defining how external programs can provide information to web servers. CGI provides a mechanism for web servers like Apache to exchange data with programming languages such as Perl.<\/p>\n<p>CGI is <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/tools.ietf.org\/html\/draft-robinson-www-interface-00\">one of the oldest<\/a> components of internet infrastructure. It\u2019s still widely used today, despite having been superseded by newer alternatives.<\/p>\n<p>Web server software was traditionally limited to serving static webpages. CGI <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">script<\/a>s enabled the production of <em>dynamic<\/em> responses, created when a request is received.<\/p>\n<h2 id=\"standardising-http-server-implementations\"><span class=\"ez-toc-section\" id=\"Standardising_HTTP_Servers\"><\/span>Standardising HTTP Servers<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>CGI was <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.w3.org\/CGI\">designed to provide<\/a> a standardised way for programming languages to access HTTP server information. Any HTTP server can be paired with any programming language, provided they both adhere to the CGI spec.<\/p>\n<p>CGI-enabled servers will handle requests using a process similar to the following:<\/p>\n<ol>\n<li>A new request is received: <code>\/example.pl<\/code>.<\/li>\n<li>The web server recognises <code>example.pl<\/code> as an executable CGI script, so it invokes the script.<\/li>\n<li>The Perl CGI script receives all the data about the request, such as its URL and HTTP headers.<\/li>\n<li>The <code>example.pl<\/code> script runs; its output will be passed back to the web server for emission as an HTTP response.<\/li>\n<\/ol>\n<p>The flow outlined above stands in stark contrast to a web server\u2019s regular operation. A basic request for <code>\/example.pl<\/code> would return the content of that file. If the file didn\u2019t exist, you\u2019d receive a <code>404<\/code> response instead.<\/p>\n<p>When using CGI, a request doesn\u2019t need to map to a real file on-disk. Instead, a user-defined program is run. The program has responsibility for generating the output to send to the client. The web server is no longer concerned with the actual content of the response.<\/p>\n<h2 id=\"information-exchanged-via-cgi\"><span class=\"ez-toc-section\" id=\"Information_Exchanged_Via_CGI\"><\/span>Information Exchanged Via CGI<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The program binary executed via CGI can access various data about the incoming HTTP request. This includes the URL, headers, query string and HTTP method, as well as the remote client\u2019s IP address.<\/p>\n<p>Server software isn\u2019t required to provide all data verbatim. The CGI specification <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/tools.ietf.org\/html\/draft-robinson-www-interface-00\">permits servers<\/a> to exclude headers from environment variables. This may be to omit sensitive information \u2013 such as the value of the <code>Authorization<\/code> header \u2013 or to avoid redundancy when the same information could be accessed using a dedicated variable.<\/p>\n<p>In addition to data about the request, CGI-compatible servers must also indicate various details about themselves. This includes the name and version of the host server software. Scripts may use these details as they see fit.<\/p>\n<p>Information is passed from the server to the CGI program as environment variables. The program accesses them in the same way as any other environment variable. The server will run the program as a child process of itself, setting the environment variables before calling the executable.<\/p>\n<p>There is one piece of data which won\u2019t be passed as an environment variable. The request body gets special treatment, as it could be extremely long. This will be piped into the script on its standard input stream. Scripts are informed how much data is available via the <code>CONTENT_LENGTH<\/code> environment variable.<\/p>\n<p>Once the script processing completes, the CGI script returns an HTTP response to the server. This must be a complete HTTP response comprising headers and an optional body. The script emits the response to its standard output stream. The server then sends the response back to the client over the HTTP connection.<\/p>\n<h2 id=\"wheres-cgi-today\"><span class=\"ez-toc-section\" id=\"Wheres_CGI_Today\"><\/span>Where\u2019s CGI Today?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>CGI helped bring about the modern web. It provided an exceedingly simple way to build dynamic server-side scripts using the technologies of the mid-90s. No longer was a webpage a static HTML file.<\/p>\n<p>CGI\u2019s simplicity has helped it to endure in the decades since. CGI scripts remain in use, particularly within legacy applications based on older languages. <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/technology\/\" data-internallinksmanager029f6b8e52c=\"4\" title=\"Technology\" target=\"_blank\" rel=\"noopener\">Technology<\/a> has not stood still though; CGI has been superseded by more modern alternatives that are better suited to today\u2019s web.<\/p>\n<p>Traditional CGI creates an overhead which becomes problematic at scale. The CGI script is reloaded on every request, spawning a new process which can exhaust resources on high-traffic sites.<\/p>\n<p>CGI\u2019s also limited in terms of the control it provides to scripts. Scripts are only able to determine the <em>response content<\/em> sent back to the client. They\u2019re unable to influence any other part of the HTTP exchange, such as authentication or session management.<\/p>\n<p>Finally, there are security concerns. CGI scripts are <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/general\/\" data-internallinksmanager029f6b8e52c=\"3\" title=\"General\" target=\"_blank\" rel=\"noopener\">general<\/a>ly executed as a child process of the server. This means the server must be protected from script interference. Misconfiguration could give a script undesirable access to other resources managed by the server, such as its configuration and log files.<\/p>\n<p>Many of CGI\u2019s issues have been addressed by newer interface technologies. <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.nginx.com\/resources\/wiki\/start\/topics\/examples\/fastcgiexample\">FastCGI<\/a> was created to reduce the CGI overhead issue. It works similarly to CGI but does not spawn a new process for each request. Instead, the FastCGI server works independently of the web server, maintaining its own set of persistent processes used to host the CGI scripts.<\/p>\n<p>Elsewhere, individual programming languages have implemented their own server interfaces. These are directly integrated into web servers, usually through optional modules. One example is Apache\u2019s <code>mod_php<\/code> and <code>mod_perl<\/code>, which offer native support for those programming languages without using CGI (even though both can be used via CGI).<\/p>\n<p>Despite the emergence of these mechanisms, CGI does remain relevant. The simplicity at the core of its design has informed most subsequent efforts to improve the overall architecture. While you\u2019re unlikely to encounter CGI day-to-day in modern web systems, major web servers continue to support it and that looks unlikely to change anytime soon.\n<\/p><\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/10386\/what-is-the-common-gateway-interface-cgi\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#What Is The Common Gateway Interface (CGI)? \u2013 CloudSavvy IT&#8221; The Common Gateway Interface (CGI) is a standard defining how external programs can provide information to web servers. CGI provides a mechanism for web servers like Apache to exchange data with programming languages such as Perl. CGI is one of the oldest components of internet&#8230;<\/p>\n","protected":false},"author":1,"featured_media":213786,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/03\/88aaea59.jpg","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-213785","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/213785","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=213785"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/213785\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/213786"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=213785"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=213785"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=213785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}