Learning PHP Part 6 : The Workings of a Web Server Running PHP Code


After successfully installing XAMPP and run the PHP file of XAMPP, PHP tutorials at this time we will learn how to work in a web server running PHP code, and understanding of PHP programming script language.

Understanding The Language Of Programming Scripts PHP (Scripting Language)

It contains the PHP programming language group called scripting language. Simply put, Script Programming Language is a type of programming language that does not require special work environment for running (Wikipedia), and generally can be inserted into another programming language code.

In the world of web programming, most of the programming language used is a type of programming language script. A PHP file contained PHP code itself, it can also contain HTML code, JavaScript and CSS, all in a PHP file.

Apache Web server will determine how do I run the script code, so needed a way to tell the web server that this “This” is the PHP code, and “it” is HTML.

How to work a Server running PHP code

Tutorial on understanding and Web Programming in PHP, we have seen what can be done to simplify HTML writing PHP. This time we will repeat the same thing with the following example:

Although the above code consists of HTML and PHP, so that the web server “want to” execute PHP code embedded in it, the file must be in the save as PHP files i.e. with the suffix *.php.

Savelah the code as way_working.php in the folder D:\xampp\htdocs\learning. Next open the browser, and type the following address: localhost/learning/way_working.php

If there is no problem, will perform the following results :

How To-Work-Sample-PHP-Web-Servers-Running PHP-Files

Next, let’s discuss the workings of the web server in handling the above code:

  1. The Web Server will see the extensions (types of) files that are accessed. If the file executed is way_working.html, then the web server will not call the PHP module to run PHP code, since the web server thinks it is a plain HTML file, and display it directly without processing. However, if the file is way_working.php, then your web server runs PHP modules, and execute PHP code within that file.
  2. Apache Web Server will start processing the file way_working.php, starting from the first row to the last row in a sequence.
  3. On the first line, the web server will find the opening HTML tag, namely <! DOCTYPE html > and followed with other HTML tags. Because it does not find the instructions to enter the mode PHP, all of these HTML tags do not require a direct process, and send to your web browser.
  4. So the web server finds the tag <?php on the line the 7th, then the tag instructs the web server to the next code that consists of a PHP code, so anything written after this tag will be processed following the rules of programming language PHP, we call only this process as a PHP mode.
  5. Starting from tag <?php is PHP mode. Inside PHP mode We will make PHP programming code. For our example above, I created a simple PHP command, namely the echo. ECHO was a command in PHP that is used to display the text that is between the two quotes () into the browser. In the example above, we use echo to display text: “<p>This sentence is made using PHP </p>”into the web browser. So you will see the text appear in the web browser.
  6. The Web server will continue to be in PHP mode to find the closing tag PHP, namely tag?> marks the end of PHP.
  7. Tag ?>In addition to indicating to break out of PHP mode, also instruct to the web server that the next text will be processed as normal HTML text.

In the example above, most of the PHP code in the form HTML code. But we can also create a file that is entirely in PHP.

As a second example, I’ll modify file way_working.php before, be the following :

How to-work-Sample-PHP-Web-Servers-Running PHP-files-2

If you are running PHP code above, the resulting display will be using exactly the same code way_working.php first. The difference is just how we process and share the page, which can be written with plain HTML code, and which ones should be written using PHP.

So which one is better? The first example uses HTML code with a bit of PHP code, or the second example that uses PHP code entirely?

You are free to use what is considered easier, although most programmers will love the writing style of the first, where we just go into the PHP mode when needed, and load web server will also be reduced because it is not continuous to process PHP.

But the speed of execution of PHP will not be able to distinguish you mostly to the PHP file as simple as above. PHP already optimized in such a way that it can be executed as quickly as normal HTML files. For example site webspoint. This site was created using WordPress which consists of thousands of lines of PHP code on every page that is displayed.

After understanding the workings of the web server in executing PHP code, in the next tutorial we will learn various ways to get into the mode of PHP than by tag tag <?php and tag ?> >. Later in the Tutorial Learn PHP: how to insert PHP code into HTML.


Please enter your comment!
Please enter your name here