Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Why html data has to be send to a different server to process?

  1. Nov 2, 2012 #1
    Since HTML is a markup language it cannot process data. So we have to send the data somewhere to produce some output. But why do we need to send it to a different server where data is processed using PHP language?
    Why can't we just have an external c or c++ program and have a way to send the data to the program and the output back to the web page?
  2. jcsd
  3. Nov 2, 2012 #2
    Flash has always been a problem because not everyone installed the plugin. Imagine if for your website to work it required all visitors to install a PHP plugin.
    Last edited: Nov 2, 2012
  4. Nov 9, 2012 #3
    Sorry for the late reply - but what I was asking was that why do we need php? I mean we already have so many languages that can process data like c, c++, java, python etc.
  5. Nov 9, 2012 #4
    You certainly can. Google and Facebook use C++. You can use Java in the form of JavaEE. PHP is most common because it was built specifically for the web. It has the modern framework. If you like C and want to take advantage of a newer framework, try C#.
  6. Nov 9, 2012 #5
    I am new to web designing and stuff so what exactly do you mean by "specifically for the web" and "modern framework"?
  7. Nov 9, 2012 #6
    When C++ was created there was no internet. The internet introduced many new computing/networking concepts. C++ can handle it all, but not in production efficient terms. Languages like PHP are streamlined specifically for web development. Functions and tools that web developers would need are all built in. In C++ you must do it all yourself, manually. There are very very few "libraries" (for web developers) at your disposal.
  8. Nov 16, 2012 #7


    User Avatar
    Gold Member

    PHP *is* an external C program that does exactly this.
  9. Nov 17, 2012 #8
    Essentially, here's what's happening:

    When you visit a website you are actually passing an instruction to the server in the form of a URL. The purpose of the server is to, well, serve you data and exactly how it does this depends on the server technology you are using (examples include Apache, IIS, nginx, and GWS). Keep in that this is meant literally, the server has no concept of HTML, images, or flash - its job is to figure out what you mean when you go to http://example.com/home [Broken] and then send information to the client (ie, you).

    Now, you interface with the server by using a server-side language such as PHP. When the server determines that you need to load index.php, it loads the PHP module to work on index.php. This is where the "language" takes over to do as you say "process data" and "produce the output".

    Notice when I said the server "loads the PHP module"; you can really have it load any module/language whatsoever, be it C++, JavaScript, QBasic, Ti-83+, the language used to power my microwave...it doesn’t matter. If no modules/languages were loaded to process the file, the server would simply spit out index.php in it’s raw form - which wouldn’t look pretty.

    Now the client (the browser) only understands HTML, CSS, and JavaScript so it is the responsibility of the server and the language to work together to process a .php file (for example) into functional HTML file that your browser can work with. This relationship between the server and language is called a Server Stack, and several exist:

    * LAMP - an Apache server that uses the PHP language
    * Ruby on Rails - typically a Mongrel server that uses the Ruby language
    * NodeJS - You actually build the server yourself using JavaScript, and then use JavaScript to process the data.

    So as you can see you do NOT need PHP.
    Last edited by a moderator: May 6, 2017
  10. Nov 30, 2012 #9
    Thanks for explaining the process. That really helped.

    I just came across something called Common Gateway Interface (CGI). I think it is related to the topic. But I don't understand what it is exactly. I think it does the same job of server-side programming but I am not clear.

    Sorry again for the late reply
  11. Dec 1, 2012 #10


    Staff: Mentor

    Assuming that we are talking about HTTP or HTTPS (Hypertext Transport Protocol, Hypertext Transport Protocol Secure), what happens is that a client (such as a web browser) sends a request to the server, and the server sends back a response. Most of the time your browser sends an HTTP GET request, and the response body contains the content (often HTML) of the page. A browser can send other types of requests, such as POST or PUT, or a few others.

    Most of the web programming languages -- JavaScript, jQuery, Ruby, and others -- provide an abstraction of these request/response transactions.

    Most of the current web browsers have built-in tools so that you can see what goes out "over the wire". Pressing F12 gives you access to the debugging tools, one part of which lets you look at all parts of the requests and responses.
    Last edited by a moderator: May 6, 2017
  12. Dec 2, 2012 #11


    User Avatar
    Gold Member

    When a browser requests a "dynamic" web page (one that needs to run a program on the server in order to generate results to send back to the browser), the web server has to hand the request to a program. Using C or C++ is risky because those languages permit risky memory management (i.e., pointers) and it is difficult or impossible to guarantee that the programmer would not make a mistake leading to the machine crashing. More "modern" web-oriented languages like PHP, Java or C# do not allow the programmer to do pointers; code for those languages executes in a virtual machine which allows the web program to be isolated (and somewhat protects any other web programs also executing at the same time on the same machine from being destroyed if one web program did something stupid).
  13. Dec 2, 2012 #12


    User Avatar
    Gold Member

    PHP is not running on a framework or virtual machine, but is (I think) interpreted, which makes it less efficient, but still, it is far "safer" for multiple programs written in PHP to execute on a web server because the programmer is not allowed to manage memory directly. C and C++ have no safety net; they are basically the same as assembler or machine language, and one ill-behaving program can crash an entire web server.
  14. Dec 2, 2012 #13


    User Avatar
    Gold Member

    Web servers these days may respond to hundreds of requests per second. That means that dozens of "web programs" may be executing on the web server at any given time. Using CGI and C, the probability of one of those web programs crashing the machine was pretty high. So CGI, C and C++ fell out of favor, and in their place, came languages which somewhat protect programmers from other bad programs by isolating their execution in separate, light-weight processes (threads). The threads are recycled for efficiency and thus don't have to be recreated. Within each thread, the program is not allowed to use a language such as C or C++ which can allow you just to jump anywhere within the (virtual) memory of a computer and screw up anything you want to (or are mistaken enough to do).
  15. Dec 2, 2012 #14
    What is CGI basically?
  16. Dec 2, 2012 #15
    I hate to say this, but pretty much everything you said is false. PHP is a framework, for one. Also, interestingly, PHP is written in C and can be extended with C or C++ http://php.net/manual/en/history.php.php

    Facebook is for the most part built in C++. In fact, you can fiddle with some of their open-sourced core libraries here: https://github.com/facebook/folly

    You also contradict yourself here with:
    I don't really know what pointers have to do with anything, but although PHP (and Java I believe) don't have "pointers" they do have references which can be used in a similar way. You can't do pointer arithmetic, but you can beat around it.

    The first part is true, but the rest isn't. You can code extensions in C/C++ that can be accessed from within PHP.

    While you're correct about the existing possibility of the server crashing due to mistakes, you wouldn't typically code an entire Web Stack in one "instance" (one program). Typically, you would have different "programs" handling different parts of the web stack to avoid or at least mitigate errors later on.
  17. Dec 2, 2012 #16
    @Avichal: I always have a hard time explaining what CGI is. It's not actually a program, but a set of rules...a standard. CGI scripts (typically coded in Perl, but can be coded in C/C++, Unix Shell scripts, etc) are used to interface the browser with the server, but in a very specific way.

    Best analogy I can come up with is this: CGI is to the server what the MLA format is to an essay.

    Maybe someone can do better lol
  18. Dec 2, 2012 #17


    User Avatar
    Gold Member

    I didn't say that one CAN'T code on a web server in C or C++--I just said that most people do NOT, and for a good reason. And if you "don't know what pointers have to do with it", then you are not qualified to comment on this thread.

    Facebook is written by a tight-knit team and optimized solely for high performance and volume; hence, its code must be very fast. That is not typical for all web sites, and today, few are written in C++ because of the dangers.
  19. Dec 2, 2012 #18
    When I ask this, I'm not being smart...I'm legitimately curious. What do pointers have to do with anything?

    As for the Facebook example, I was merely pointing out that C++ is useable. Your posts made it seem as though C++ is dangerous, or as you say "unsafe", which it isn't.

    People use frameworks because it saves time, is far easier, and generally more efficient than if you tried to code it yourself - not because of the "dangers".
  20. Dec 3, 2012 #19


    User Avatar
    Gold Member

    Use of pointers in C or C++ is what leads to memory leaks. Any time one allocates memory, a pointer must be used to track it. Failure to release used memory is one of several causes of crashes in C programs.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook