PHP Performance Discussion and testing

Source: Internet
Author: User
Tags memory usage

1. Origin

About PHP, a lot of people's intuitive feeling is that PHP is a flexible scripting language, library class rich, easy to use, safe, very suitable for web development, but low performance. Is the performance of PHP really as bad as everyone feels? This article revolves around such a topic to discuss. From the source code, application scenarios, benchmark performance, comparative analysis of several aspects of the performance of PHP in-depth analysis, and through the real data to speak.

2. Analyze PHP performance from the principle

From the principle analysis of PHP performance, mainly from the following aspects: memory management, variables, functions, operating mechanism to carry out the analysis.

2.1 Memory Management

Like Nginx memory management, PHP is also based on the memory pool, and introduces the lifecycle concept of the memory pool. In the memory pool, PHP hosts all of the memory-related operations of PHP scripts and extensions. The management of large memory and small memory adopts different implementation methods and optimization, and can refer to the following documents: HTTPS://WIKI.PHP.NET/INTERNALS/ZEND_MM. During the lifecycle of memory allocation and recycling, PHP uses an initialization application + dynamic expansion + memory identity recovery mechanism, and mask the memory pool directly after each request is completed.

2.2 Variables

As is known to all, PHP is a weak variable type language, so inside PHP, all PHP variables correspond to a type zval, which is defined as follows:

Figure A PHP variable

In terms of variables, PHP does a lot of optimization work, such as reference counting and copy on writer mechanism. This ensures optimal memory usage and reduces the number of memory copies (refer to http://blog.xiuwz.com/2011/11/09/php-using-internal-zval/). In the array aspect, the PHP internal uses the efficient hashtable to realize.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.