Posts

How PHP Works

In this lesson we’ll look at what PHP is, how it works, and what it is for. To begin with, a program written in PHP during its operation is not a standard window that we are used to seeing. In the vast majority of cases, this program runs on the server “invisibly.” That is, we cannot control it at runtime, but in fact we don’t need it.

The fact is that this program should accept a request from the user, take some action, give the user the result, 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 respond to them in real time.

PHP does not work on its own. To work with the user, it must be configured in conjunction with a web server, for example, Nginx or Apache. If in a simple way, then the user sends a request to the web server via HTTP. The web server determines what type of file was accessed, and if it is a file with the .php extension, the web server sends a request for processing by the PHP interpreter, the script is read, converted to byte code, executed and returns a web response to the server. The web server passes the generated result to the user. This result, as a rule, is a dynamically generated HTML page.

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

It is worth mentioning 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, and working with files. All this is actively used by modern sites.

You probably already managed to think about the fact that in order to run the program in PHP, you have to tinker with the configuration, because you need to connect it to a web server. Fortunately, there are ready-made solutions that allow you to start a web server with PHP in a few minutes. And modern hosting allows you to upload and run projects in PHP, without thinking at all how everything is arranged there. And this is good, because you are a programmer, not a system administrator. I ask you to accept this, this 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 turnkey solution as a server, which I advise everyone to use, is called OpenServer. But also you can use XAMPP (including a Mac version), WampServer and Web.Developer. We will talk about how to install and run OpenServer in the next lesson.

Download Openserver (yes, it’s for free)

/ April, 11 at 14:11

I create web projects, develop, optimize and promote websites. If you have any ideas or want to suggest something, then write to me and my team.

Top ↑

Leave a Reply