How PHP Works


If we want to look at HTML:
1. The user requests a page with ‘clean’ html
2. The server checks if the page exists
3. if there is – returns the .html page to the user as it was on the server.
 
If we access the page with PHP code:
1. The user requests the page e.g. index.php
2. The server sends the file to a handler that will execute the php code
3. The PHP handler sends the resulting code to the server
4. The server returns the requested page to the user as html

How is PHP set up? The most important files:
 
php5ts.dll – kernel // here are the main PHP functions
php.ini – configuration file
php.exe – PHP command line
php5apache2_4.dll – PHP module for Apache
The /ext/ directory contains the extensions; PHP supports about 5000 functions.
 
The PHP module is bound to Apache in the configuration file:
conf\httpd.conf
LoadModule php5_module “..php/php5apache2_4.dll”.
AddType application/x-httpd-php .php // which files to give to the handler

A note in the margin:

Is it possible to embed php-code in a .html page?
The answer is yes, but only by setting directives to the server; for example, through .htaccess:
AddHandler application/x-httpd-php .html .htm
or
AddHandler x-httpd-php5-cgi .html

PHP – an embeddable language, ie, in the php file not everything must be an executable php-code, there can be html, js, etc. Example:

<p>Эwill be ignored by PHP and displayed by the browser.</p>
<?php echo 'And this will be processed.'; ?>
<p>This too will be ignored by PHP and displayed by the browser.</p>

or

echo "Hello world";
// ... more code
echo "The last expression";
// The script ends here without the PHP closing tag

To get a better idea of how the interpreter works, here is an illustration:
We have a file where half of the text is in Russian and half in English. Our task is to translate all the text into Russian. Similarly, the interpreter looks at the .php file, which consists of html (Russian) and php-code (English; it must be processed, “translated”).


This entry was posted in Apache (en), PHP (en). Bookmark the permalink.

Leave a Reply

🇬🇧 Attention! Comments with URLs/email are not allowed.
🇷🇺 Комментарии со ссылками/email удаляются автоматически.