What is PHP and what is it used for?
PHP is a programming language that runs on the server. It decides what happens with your input, fetches data from a database and uses it to build the page your browser displays. This text explains what that means in practice.
What you will learn
Browser and server: two different places
Every web page is created in two places. One is your device: that is where the browser runs, displays text, reacts to clicks and executes JavaScript. The other is the server: a machine in a data centre that many people access at the same time. That is where the data lives, where the rules apply, and where PHP runs.
This separation is not a technicality; it is the reason behind almost all the properties of web applications. Whatever happens in the browser can be altered by any visitor — it is a program running on their device. Whatever happens on the server stays under your control. That is why price calculation, permission checks and anything that must be binding belong on the server.
What PHP does during a request
PHP is started when a request arrives and ends when the response has been written. In between, the real work happens: validating input, clarifying permissions, reading or writing data, querying other systems and assembling the response.
- 1BrowserThe form is filled in and submitted.
- 2Web serverAccepts the request and passes it to PHP.
- 3PHPValidates the input, makes decisions and prepares the response.
- 4DatabaseStores the transaction or returns stored data.
- 5ResponseThe browser receives the finished page or a confirmation.
This sequence repeats for every request that actually reaches PHP. Not every delivery does: images, stylesheets and cached pages are served by the web server directly, without starting PHP. Where that line runs is decided by the architecture of the application. PHP remembers nothing between two requests; whatever needs to persist is kept in a database or in the user's session. That sounds cumbersome, but it has a practical advantage: an error in one request does not affect the next, and a server can handle a great many requests side by side.
Where PHP is used today
PHP is found in web applications that process data and model business processes. We come across three groups most often in everyday work:
For our own work, the third group is the most interesting: it is rarely shown, yet accounts for a large part of the benefit. You can see a user interface; you notice a working data transfer by the fact that nobody has to enter data twice any more.
An example from practice
A leave request in the employee portal
An employee picks two dates and submits the request. In the browser, the only thing you notice is that the form pauses briefly. On the server, PHP checks during that time: Are the dates valid? Is the period within the current year? Is there any leave remaining? Who is the responsible manager?
Only then is the request saved, a notification triggered and the page returned with the updated status. None of these checks is binding in the browser — whatever runs there can be altered. As immediate feedback a check in the browser is useful and makes the form easier to fill in; it must not decide. The binding check happens on the server, for every request. That is why a seemingly simple form means development effort: the form is the small part, the rules behind it are the big part.
Where PHP is not the right choice
PHP is built for requests that are answered and completed. For permanently open connections, such as a chat with instant delivery to many participants, or for very compute- and memory-intensive long-running jobs, there are often better-suited tools. PHP can indeed be run as a long-running process for these purposes, but that requires a different architecture from the usual request model. Anything that needs to react immediately in the browser also remains the job of JavaScript.
In practice, this is rarely an either-or question. An application usually consists of a PHP application for the business logic, JavaScript for the user interface and a few additional services for special tasks.
Why the version matters
PHP continues to be developed, and each version receives security updates for only a limited time. Which versions those currently are is published by the project itself — the list below links to it. If an application runs on an unsupported version, it no longer receives security fixes. This is the most common reason why a working application still needs work.
Common misconceptions
Further sources
- PHP manual (German-language) official documentation of the PHP project
- Supported PHP versions which versions still receive security updates
About the author
Fabian Lücker is managing partner of PHP-Schmiede KG in Rheine and has worked in software development since 2007. He is responsible for development and design, and writes here about decisions that arise in real projects.
Have an application in mind, but no specification yet?
For an initial conversation, a description of your task and the most important processes is enough.