PHP, a language for building web pages on a server

Le langage de programmation PHP

Sometimes you are told how to optimize a language to speed it up, and Facebook even took a radical approach by creating a compiler and virtual machine.
But this language has become universal on the server side. PHP is P in the popular LAMP architecture, which includes the Linux operating system, Apache server, and MySQL database.

PHP script creates HTML pages and can be embedded in HTML code, such as JavaScript, but interpreted on the server. A translator can also work at a local station.

The language was developed in 1993 by Rasmus Lerdorf, as he himself needed a free tool for programming web pages and distributed it in a free source called PHP/FI, Personal Home Pages/Form Interpreter.

"I never thought, writing PHP, that one day millions of people would look at my code over my shoulder. If I had imagined it, I would have done some things differently.'
Rasmus Lerdorf, 2012.

After working at Yahoo! Rasmus Lerdorf was hired by WePay and then Etsy. He would then develop PHP with the help of several programmers who write a new engine for PHP 3 and give it the name PHP Hypertext Processor in 1997. Recursive abbreviations are fashionable, with names such as GNU is Not Unix, PNG is Not GIF, etc.
In 1999, a Zend engine was created for PHP 4.
PHP 5 appeared in 2004, it is object-oriented and supports XML. The execution speed was doubled from PHP 5.3 to PHP 5.6.
PHP 7 appeared on December 3, 2015. There is no PHP 6 after an aborted project that received part of its contribution to PHP 5.

Language description

PHP repeats C syntax and Unix shell ideas.

Syntax

Control structures

The if structure has elsive and else variants.

if(x < 10) {
   echo "$x inférieur à 10\n";
}
elseif(x > 10) {
   echo "$x supérieur à  10\n";
}
else { echo 'etc...\n' }
Willow structure:
while(expr) {
    ... 
} 

Function or method

The function definition begins with the function keyword, followed by the name and a comma-separated list of arguments, and the body is between {and}.
The return keyword in the definition body returns a value.

function nomfonc( arguments ) {
...instructions... return(x);
}

Class

class nom {
    ...
}

The body is like a global code.

Line

Example: Displaying letters of text .

$str = "demo";
$len = strlen($str);
for($i = 0; $i < $len; $i++) { 
     echo $str[$i];
} 

Picture

Declare, merge, take subassembly, show elements.

$arr = array(1,2,3 );
$arr = array_merge($arr, array( 4,5));
$sub = array_slice(|$arr, 1,3);
foreach($sub $as $num) {
     echo $num;
} 

234 should be displayed .

Integrated local server

For local work, in particular for code development, you need to install a server, and then execute the script with the prefix http ://localhost.

Since version 5.4, this becomes superfluous, since the local server is included in the distribution kit. The server is started with the following command:

php -S localhost:1100

Where 1100 is the port number (here is an example). To run the index.php script and show the result in a browser, enter in the URL string:

localhost:1100 

The advantage over solutions such as Wamp is that there is no need to transfer files to the Wamp subdirectories, the www directory in this case. PHP scripts and pages work where they are.

Why use PHP? User experience

PHP is an Internet tool running on a server to execute scripts or create or edit web pages in which it is included.
It is suitable for processing important server-side data and creating HTML pages that display results (JavaScript is suitable for dynamic editing of browser-side pages).
PHP 5 is a competitor to Java in its simple form, as an application server, and is a platform for web applications and services.
This is the most used language for creating CMS, content management systems.

The language was developed daily to add the necessary features, without a clear plan. In this regard, there is a lack of consistency, clear rules, and it is necessary to constantly refer to the manual in order to find, in particular, the parameters of the function .
For example, the substr_replace function has a starting chain followed by a substitutable part and an alternate string as arguments, while the str_replace function has a substitutable part and an alternate string followed by a starting string as arguments.
The fact that a table is also a dictionary, so hints are keys, is a source of headaches for programmers.

In fact, there are many alternatives: Python, Ruby, Node, Go, and most recently Julia.

PHP 6

(actually PHP 5.x)

The PHP 6 project, which was supposed to use the Unicode encoding format, has been discontinued. But some of the features provided by the project are included or will be included in PHP 5.

  1. Namespaces.
  2. Generators and coroutines (PHP 5.5 ).
  3. XMLReader. To read XML files in Sax progressive mode.
  4. XMLWriter.
  5. goto, the Basic language directive reappears.
  6. Lambda functions or closures (unnamed).
  7. Filefinfo extension for the file system.
  8. Headlights. Allows you to place a PHP application in one executable file, as is done in Java with .jar.
  9. Intl. Internationalization.
  10. The continue and break operators can work only with constants or without parameters.
  11. The function ereg () for regular expressions will be removed. It needs to be replaced by preg_match (), which has a different format but is used more broadly.
  12. Compatibility with older formats such as GD 1 and Freetype 1 will be removed.
  13. Magic_quotes, a very described property, because the source of security flaws will no longer be supported.
  14. The same goes for register_global, safe_mode and register_long_arrays.
    Thus, existing applications will need to be modified to ensure compatibility.
  15. Lighthouses <? php?> - the only recognizable ones .
  16. dl () to load dll is disabled from 5.3
  17. .
  18. Array_column returns a column in a multi-dim array.

Support for Windows XP ends with version 5.5.

In 2008, the CEO of Zend stated this in an interview:

So, we are planning a long-term rollout cycle for PHP 6 and don't want to go down the same path as the Perl project, with the co-authors still working on Perl 6 six years later. People laugh at Microsoft, but watch Perl 6.

In 2015, PHP 6 still does not exist, and we preferred to switch directly to PHP 7. To be honest, Perl 6 is also not yet completed!

PHP 7

Previously named PHP Next Generation (PHPNG), this new version replaces PHP 5 (PHP 6 will never be), and on the one hand, it wants to speed up work with the JIT interpreter, as HHVM does, on the other, to make the syntax more consistent. Performance gains average 100% over 5.6.
Asynchronous programming provides parallel processing.

Do I need to switch my site to PHP 7? This improves performance and memory savings, so it's definitely recommended. However, you need to make sure that there is no incompatibility, since the set of outdated but still active functions has already been removed. For example, mysql functions.

PHP Optimization: Google vs. PHP Team

Google experts give advice to webmasters on optimizing page and script code. One of these articles concerns PHP and in several points indicates how to change the code, replace control structures, optimize it at best.
But on the part of the language's creators, we rebel and challenge that analysis. This controversy is interesting for webmasters who use PHP on their site, as it provides useful explanations on code optimization.

The only thing that both sides agree on is that it is better to migrate to the latest version of PHP, as it is always the fastest.

HHVM

HHVM (Hip Hop Virtual Machine) is a JIT compiler created and used by Facebook, available on GitHub with source code. Working with the HHVM virtual machine, PHP becomes two faster than with the Zend interpreter. HHVM has replaced PHP 5.3 in Wikipedia (now preparing to migrate to PHP 7).
Comparisons with PHP 7 showed that HHVM is slightly faster for the previous code, but when the code uses the novelty of the language, the PHP 7 interpreter wins it.

To analyze its work - a detailed article: LLVM generation code in HHVM. LLVM is now the final backend in the intermediate view chain.

De PHP à LLVM avec HHVM

PHP is compiled into HHVM bytecode and then into a second intermediate representation. Then it is translated into an assembly language that can be converted into LLVM bitcode.

The virtual machine works with the Hack language, which replaced PHP and became incompatible with it in 2018. It can be replaced with PHP 7 without loss of performance .

Tools and tutorials

Free publishers and IDEs

Most code editors are syntactically colored and self-corrected for PHP, Visual Studio Code for example. Some FDIs offer additional tools.

Development assistance

Scripts and tutorials

See also: PHP frameworks.

Discussion board

What's the best PHP editor?

26-01-2009 19:04:41

Fodart

There are a number of editors for PHP, but I would like to know if anyone knows a PHP editor with autocomplete and everything that can be found on modern editors... I'm running Windows, but sometimes I'm running Linux.
28-01-2009 14:47:48

webmaster

Sun decided to extend its NetBeans IDE to languages other than Java, specifically PHP, JavaScript, and C++. What makes this free software very complete, even integrating a server to test PHP scripts offline! This is probably the most complete. Runs Windows and Linux.