PHP, as an explanatory language, has a performance gap with compiled languages such as Java and C ++. how can we improve PHP efficiency?
Source: Internet
Author: User
I hope PHP experts will discuss it and hope PHP experts will discuss the reply content: facebook tells us that to improve PHP efficiency, it is best to change the syntax, then I made HHVM about this problem. I actually want to come in and talk about it.
In general, the simplest way to improve efficiency is to pay attention to a lot of php efficiency optimization skills during development. Such as algorithms, syntax, and architecture. These methods can be accumulated both in experience and on the Internet.
If you find that the bottleneck of efficiency is not anything that doesn't matter. Some functions are slow down on some functions and functions, and OK. if there is any problem, you can solve it by using C extension. However, there are many associated problems, such as the business logic may change due to the C extension method.
Or you may find that the explanatory language like PHP is slow, where is it slow (laugh), how is it broken. This provides an accelerator. you can use the cache operation code to avoid parsing some related introductions and explanations.
Three free PHP accelerators: APC, eAccelerator, and XCache
Alternatively, we can change to a binary language for faster execution. You can see the following solutions. C (Roadsend and SCC), c ++ (hiphop), java (Quercus), and c # (Phalanger ). Taking hipop as an example
Facebook/hhvm · GitHub . It is the predecessor of facebook's hhvm. it is actually converting php into highly optimized C ++ code and then compiling it with g ++. There are also some other code transformer. These methods are used to convert php into another language in essence. However, this product is difficult to deploy, difficult to use, difficult to debug, and the long compilation time is simply against humanity.
I think hhvm, the one who combines the above advantages, was born.
Hhvm is actually an improved version of HipHop. Currently, the stable version is 2.3, and the performance is higher than that of HipHop 40%. Http://hhvm.com/
The language is unclear. here we will not talk about the principles of zend and hhvm. I think if hhvm is to be compared with zend, it means that if hhvm enables jit, hhvm can directly execute the machine code. Although zend caches opcode, it still needs to call C to execute the machine code.
There are many related documents online. the subject can take a look
The subject can also look at this solution HippyVM It is said that it is specially used to face Facebook.
Official claims that PHP is faster than native PHP 7. x is faster than the hhvm of Facebook 2x
Paste a picture on the official website
I have not tested either.
Pypy is awesome.
I don't know if facebook will feel beaten ~ (Partition _ tables)
I hope you can correct the mistakes. By the way, php is the best language in the world (laugh). phpNG finishes this post. PHPNG, HHVM, YAF, Baidu ODP, and Swoole actually say php has poor performance, I don't know how many teenagers have never used php. How poor is the performance of c development frameworks like yaf and phalcon? In addition, I am still struggling with the explanatory language, so I don't know the opcache thing at all. now, php is automatically precompiled once it runs. 0. Have you ever encountered a bottleneck of this degree?
1. PHP 7. stay tuned ...... Transform it into a static language! Although php is a generic programming language, it is still used for web development in 99.9%, so the bottleneck is generally not on the php side, but on the network I/O, such as the db layer.
I will first use tools like xhprof for optimization. MeasurementTo find out the most time-consuming part: most of them are called in db, such as the number of PDO connections, which can be reduced by optimizing the code.
In addition, the optimization of the db layer is generally to add an index. by analyzing the executed SQL statements (preferably log) and explain, you can add a composite index as appropriate and overwrite the index as well. Although adding indexes will affect the insert efficiency, writing is still in line with the 28 rule.
Finally, as the system becomes more complex, you need to optimize the architecture to improve performance, such as adding cache between db and app, and asynchronization of time-consuming tasks.
------ There are too many things to write here. I just want to talk about it in a general sense --------
From the perspective of the php language, development usually uses the framework, and the framework will inevitably consume, so there will be an excellent mvc framework written by extension php such as phalcon and yaf;
Php's hhvm is another way to improve php performance. it may bring better performance than frameworks like phalcon and yaf, but it is a bit difficult to set up a new portal, therefore, when the php community is quite mature, most people will not choose hhvm, which is highly risky. Even a framework written in C language such as phalcon has a high risk of using it for a relatively small team. it cannot handle the C language and has a serious problem ~~ Directly use hhvm, Facebook, or an asynchronous framework.
However, in general PHP application scenarios, the performance does not depend on PHP itself. Swoole: asynchronous, parallel, and distributed extension of PHP
Images and truth
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