PHP, a language for building web pages on a server

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.
- C syntax, the fewer typed variables, the more :
- Dynamic variables on $.
- Oriented objects.
- Associative tables (tables with search keys).
- Foreach construct for scanning tables.
- Animate String - You can place variables in character strings .
- It has a large number of functions designed for websites and databases.
Syntax
- The language is not case sensitive.
- Variables are denoted by $ and no type is specified.
- Literal strings between "" are evaluated for special codes and variables, between "" - not.
- <? php and?> PHP programs must be enabled .
- # or//run the comment.
- array («1» =>» «a,...) - dictionary.
- const is added in PHP 5.6.
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.
- Namespaces.
- Generators and coroutines (PHP 5.5 ).
- XMLReader. To read XML files in Sax progressive mode.
- XMLWriter.
- goto, the Basic language directive reappears.
- Lambda functions or closures (unnamed).
- Filefinfo extension for the file system.
- Headlights. Allows you to place a PHP application in one executable file, as is done in Java with .jar.
- Intl. Internationalization.
- The continue and break operators can work only with constants or without parameters.
- 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.
- Compatibility with older formats such as GD 1 and Freetype 1 will be removed.
- Magic_quotes, a very described property, because the source of security flaws will no longer be supported.
- The same goes for register_global, safe_mode and register_long_arrays.
Thus, existing applications will need to be modified to ensure compatibility. - Lighthouses <? php?> - the only recognizable ones .
- dl () to load dll is disabled from 5.3 .
- 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.
- The language supports argument types and function return.
function mult(float $a, float $b) : float { return $a * $b; }
- <=>The operator (space operator) is added. It returns 0 if the two values being compared are equal, 1 if the former is greater than the latter, and -1 otherwise.
- Generator, with keyword yield.
- Constant table, enumeration type.
- Fences (see dictionary).
- unserialize () function with filters for security .
- Unicode.
- List of new reserved words: bool, int, float, string, digital, NULL, TRUE, FALSE, resource, object, mixed .
- The list structure () does not always follow the same order of variable assignment.
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.
-
Copy variables or not?
In fact, PHP optimizes the assignment, and the value of the variables is physically copied only when changed. -
Single or double quotes?
It makes no difference. Even if there are variables that need to be interpreted in strings in double quotes, this is no more than when combining variables and ends of strings. -
Echo or seal?
The execution speed is similar, but in some cases it may depend on the server configuration.
(The question of speed, let's clarify, is useful when creating pages from commands in PHP.) -
Switch/case or if/else?
Again, the use of one or the other code does not matter, since the internal code is the same.
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.
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.
- NetBeans
IDE from Sun to Java for PHP and other languages. NetBeans benefits from a server built into PHP, provided that execution is configured in the project properties. Then we can run the current script from the editor and see the result displayed in the default browser. - Aptana Studio
Enables the PHP editor. (Windows) - IDE eclipse
Extension to Eclipse for PHP environment.
Development assistance
- Php.net
Official site where to find the executable file and sources . - Hack.
Statically typed version of PHP, compatible with PHP until 2018, written by Facebook. - HippyVM
Another virtual machine that is faster and creates a bridge with Python . - EasyPHP
Complete and easy installation with Apache for local programming. - XAMPP Server
Another local Windows Apache Linux PHP server. Put your PHP scripts in the HTML subdirectories of the Xampp installation directory or www for Wamp and they can work like on a real server with MySQL and PhpMyAdmin or SQLite Manager queries for database management! - Xdebug
Interactive debugger for PHP. - PHP France
Forum in French.
Scripts and tutorials
- SQL tutorial with PHP and MySQL.
Learn how to execute PHP scripts for using SQL on the site, with examples. - JavaScript в PHP. How to integrate the V8 compiler with PHP.
See also: PHP frameworks.
What's the best PHP editor?
Fodart
webmaster