Chat in Telegram

How PHP works

30.05.2021 at 15:45
66
+1

Greetings! In this tutorial we will take a look at what PHP is, how it works and what it is intended for.

Let's start with the fact that a program written in PHP, during its operation, is not the standard window that we are used to seeing. In the vast majority of cases, this program runs "invisibly" on the server. That is, we cannot control it at runtime, but in fact we do not need it :)

The fact is that this program must accept a request from the user, do some action, return the result to the user, and then exit. And the faster it works, the better. This is the main difference between PHP programs and "standard" programs that constantly hang in memory, wait for user actions and react to them in real time.

PHP doesn't work on its own. To work with a user, it must be configured in conjunction with a web server, for example, Nginx or Apache. To put it simply, the user sends a request to the web server over the HTTP protocol. The web server determines what type of file was accessed, and if it is a file with the .php extension, then the web server sends a request to be processed by the PHP language interpreter, the script is read, converted into bytecode, executed and returns a response to the web server. The web server sends the generated result to the user. This result is usually a dynamically generated HTML page.

This process can be significantly accelerated by connecting an accelerator extension. It is engaged in caching the resulting bytecode, and while the file remains unchanged, its execution immediately begins. Since PHP 5.6, the OPcache accelerator is included in the distribution by default.

It is worth mentioning here why PHP is so good for web development - by default it contains a huge number of tools for working with queries, tools for working with a huge number of databases, working with files. All this is actively used by modern sites.

You have probably already thought that in order to run a program in PHP, you will have to tinker with the configuration, because you need to connect it to a web server. Fortunately, there are out-of-the-box solutions to get you up and running with PHP in minutes. And modern hosting allows you to upload and run projects in PHP, without even thinking about how everything works there. And this is good, because you are a programmer, not a system administrator. I ask you to accept this, it will allow you to grow as a programmer much faster. Of course, over time you will have to delve into this area, but I ask you not to do this now - devote yourself to programming.

The ready-made solution as a server, which I advise everyone to use, is called OpenServer. We will talk about how to install and run it in the next lesson.

loader
30.05.2021 at 15:45
66
+1
Homework

Answer, what are the differences between PHP programs and ordinary "windowed" programs.

Comments
New comment