Monday, 18 June 2018

PHP 7 Performance And Security


PHP is widely used for custom software development. Usage statistics indicate that PHP accounts for over 80 percent of all websites, topping 240 million sites according to the Netcraft web server survey. PHP 7 (2015) is the most important revolution for PHP since the release of PHP 5 in 2004. The speed of PHP 7 and security improvements alone make upgrading to PHP 7 worthwhile. In this post, we will discuss these improvements in more details.

PHP 7 is based on the PHPNG engine (or Zend Engine 3.0) that speeds up PHP applications more than the previous PHP interpreter (Zend Engine 2.0). Thanks to PHPNG, your apps see up to 2x faster performance and 50% better memory consumption than PHP 5.6, allowing you to serve more concurrent users without adding any additional hardware. This means that your server returns pages to your users twice as fast. It also means that a single server can handle twice as many requests and you could need half as many servers in order to serve the same number of customers at the same speed as they did before. It has an impact in terms of real-world dollars.

With the major release of PHP 7.x, PHP's performance has been drastically improved in various frameworks, eCommerce and CMS platforms. Zend has done performance test on varioud apps for php 5.6, php 7 and HHVM 3.7. Improved excecution time, more than 2x faster compared to PHP 5.6. Memory consumptions are decreased by 30%.

What is HHVM?

Due to performance issues with PHP the team at Facebook developed the HipHop Virtual Machine (HHVM). It is a system that uses just-in-time (JIT) compilation to convert PHP code into a machine language to establish a synergy between the PHP code and the underlying hardware that runs it.

As per perfomance benchmarks transactions in Magento are 3x faster, Drupal 8 is 72% faster in PHP 7. Wordpress requests using 100M CPU instructions in PHP 5.6 can now do the same job in just 25M CPU uses in PHP 7. Frameworks like Laravel and Zend has shown a very well perfomance using PHP 7 as compared to PHP 5.6. Compared to other dynamic web page languages like python, perl and ruby etc., PHP has been faster and with PHP 7 it's even much more faster.




Source: http://www.zend.com/en/resources/php7_infographic

Following are the new features added to PHP 7 that improved the quality of the language, saves development time, etc.

- Scalar Type Declaration
- Return Type Declaration
- Null Coalescing Operator
- Spaceship Operator
- Constant Arrays using define
- Annonymus Classes
- Unicode codepoint escape syntax
- Group use declarations
- intdiv() New integer division function
Following has been deprecated in PHP 7

- Static calls to non-static methods
- PHP 4 style constructors
- password_hash() salt option
- ldap_sort()

PHP 7 is new and the most decorated dynamic web page language of current times ;)

Friday, 8 June 2018

PHP and Zend Engine

What is Zend Engine ?

The Zend Engine has been the core scripting engine of PHP since PHP version 4

The Zend engine is a set of components that make PHP what it is. The most important Zend engine component is the Zend Virtual Machine, which is composed of the Zend Compiler and the Zend Executor components. We could also add the OPCache zend extension in such category. Those three components are the heart of PHP (or the brain, you choose), they are critical and they are the most complex parts of all the PHP source code. In the current chapter, we’ll try to open them and detail them.


Zend's History with PHP


Zend's contribution to PHP began in 1997 when Zeev Suraski and Andi Gutmans started work on a rewrite of the core scripting engine of PHP. This work helped to redefine PHP as a full-featured development language.

Zend's contributions continued with PHP 4 which saw the introduction of the Zend Engine, a highly optimized execution engine. This enhancement allowed modules such as debuggers, performance boosters and custom loaders to dynamically extend PHP for a broader range of functionality. Whenever you're using any plug-in module today, you're doing so thanks to the extensibility support of the Zend Engine. In addition, the Zend Engine provides memory and resource management, and other standard services for the PHP language. Zend continued its work on PHP and Zend engine with the introduction of Zend Engine 2. Zend Engine 2 debuted in PHP 5.0 and added a robust and extensible object model and even more performance enhancements.
In PHP extensions are known to be "Zend extentions" and modules are known to be "PHP modules.

In traditional life, we talk about “PHP extensions” versus “Zend extensions”.
The thing that differentiate them is the way they are loaded :
  • PHP extensions (aka PHP “modules”) are loaded in INI files as a “extension=pib.so” line
  • Zend extensions are loaded in INI files as a “zend_extension=pib.so” line
First of all, Zend extensions are compiled and loaded the same way as PHP extensions.

Sources:
- www.zend.com
- www.phpinternalsbook.com

PHP 7 Performance And Security

PHP is widely used for custom software development. Usage statistics indicate that PHP accounts for over 80 percent of all websites, toppi...