PHP Introduction

This tutorial will help you learn about PHP, its short history, and how it can be used.

 

What is PHP?

A recursive acronym for "PHP: Hypertext Preprocessor." It is a widely used open-source HTML embedded server-side and general-purpose scripting language for developing dynamic and interactive web applications. You can use PHP to manage dynamic content, session tracking, databases, and even build entire e-commerce sites. With its use, you can easily interact with database servers and manage the page content in accordance. 

 

Short History of PHP

Rasmus Lerdorf created this simple yet powerful language in 1994. Originally, PHP stood for Personal Home Page and was specifically used to track visitors. 

 

Why Should We Use PHP?

This general-purpose scripting language is used for developing interactive and dynamic websites. This server-side language makes it is easy to add functionality to web pages. You can use PHP to:

  • Receive data from forms
  • Work with databases
  • Generate dynamic page content
  • Send and receive cookies
  • Create sessions
  • Send emails

 

How works PHP internally?

The PHP programming language is powered by the internal compiler and runtime engine known as the Zend Engine. PHP operates in a manner that separates each execution, with no shared resources or memory among them. The internal workings of PHP involve a series of key steps, including Tokenizing, Parsing, and Compiling.

Let's see, the PHP compiler processes the PHP code and constructs a collection of intelligible components recognized as tokens.

For example

<?php

echo "Hello world";

?>

This will converted to:

<?php to T_OPEN_TAG

echo to T_ECHO
"Hello world" to T_CONSTANT_ENCAPSED_STRING

?>

Link for all parser tokens.

The arranged tokens are structured in the form of a tree and referred to as AST (Abstract Syntax Tree).

 

AST (Abstract syntax tree): An AST, which stands for Abstract Syntax Tree, is a graphical representation of a computer program's source code that illustrates its structure. The tree's nodes correspond to each individual component found within the source code.

For example

<?php

echo 5+5;

?>

This AST will look like below:

operation => ECHO,
operand => expression (
    operation => ADD,
    operand1 => 5,
    operand2 => 5
)

PHP has the capability to transform the tree structure into Opcode, which is an intermediate representation.

The virtual machine executes the Opcode, which is the specific operation code.

 

The OpCode cache is a crucial aspect of PHP performance. In each request, you may encounter the same processes, leading to a significant bottleneck. Re-compiling PHP syntax into opcode for every request hinders performance, rendering fresh execution futile. The solution is the Opcache. When you send a request to 'x.php,' PHP parses, compiles, and executes it. The subsequent request retrieves and executes the opcode directly from the cache, improving performance.

 

Apart from this, you can use it for many more functions. Many hash functions can be used to encrypt users' data, which makes PHP more secure and reliable. In addition, it can be run on all major operating systems and is supported by major servers. It allows you to use a diverse range of databases. Above all, it is free to use and download.