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

In summary, PHP is a language that can be used to process data on a different server than where HTML is produced.
  • #1
Avichal
295
0
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?
 
Computer science news on Phys.org
  • #2
Avichal said:
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?

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:
  • #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.
 
  • #4
Avichal said:
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.

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#.
 
  • #5
I am new to web designing and stuff so what exactly do you mean by "specifically for the web" and "modern framework"?
 
  • #6
Avichal said:
I am new to web designing and stuff so what exactly do you mean by "specifically for the web" and "modern framework"?

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.
 
  • #7
Avichal said:
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?

PHP *is* an external C program that does exactly this.
 
  • #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 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:
  • #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
 
  • #10
OMGCarlos said:
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).
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 let's you look at all parts of the requests and responses.
OMGCarlos said:
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 and then send information to the client (ie, you).
 
Last edited by a moderator:
  • #11
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).
 
  • #12
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.
 
  • #13
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).
 
  • #14
What is CGI basically?
 
  • #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:
harborsparrow said:
code for those languages executes in a virtual machine which allows the web program to be isolated
with
harborsparrow said:
PHP is not running on a framework or virtual machine

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.

harborsparrow said:
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).
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.
 
  • #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
 
  • #17
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.
 
  • #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".
 
  • #19
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.
 

1. Why can't the data be processed on the same server as the HTML page?

The main reason for sending HTML data to a different server for processing is to optimize performance. Processing data on the same server as the HTML page can slow down the page's loading time, resulting in a poor user experience. By offloading data processing to a different server, the HTML page can be loaded faster, providing a better user experience.

2. Can't the data be sent to a local server for processing?

In some cases, it is possible to send data to a local server for processing. However, this is not always the most efficient option. Local servers may not have the necessary resources or processing power to handle large amounts of data, leading to slower processing times. Additionally, using a remote server allows for more flexibility and scalability.

3. What are the security implications of sending data to a different server?

Sending data to a different server for processing does come with some security implications. It is important to ensure that the server is secure and that proper measures are in place to protect the data being sent. This can include encryption and authentication protocols to prevent unauthorized access to the data.

4. Can't the data be processed on the client-side?

In some cases, data can be processed on the client-side using scripting languages such as JavaScript. However, this method is limited in its capabilities and may not be suitable for more complex data processing tasks. Additionally, processing data on the client-side can also slow down the page's loading time, similar to processing on the same server.

5. Is it more expensive to send data to a different server for processing?

Sending data to a different server for processing may incur some additional costs, depending on the specific server and resources being used. However, in most cases, the benefits of faster processing times and improved performance outweigh the cost. Additionally, there are often cost-effective options available for data processing, such as using cloud-based servers.

Similar threads

  • Programming and Computer Science
Replies
7
Views
455
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
12
Views
9K
Replies
14
Views
2K
  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
19
Views
2K
  • Programming and Computer Science
Replies
14
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
726
  • Programming and Computer Science
Replies
1
Views
625
  • Computing and Technology
Replies
3
Views
2K
Back
Top