search
HomeBackend DevelopmentPHP TutorialPHP 作为解释性语言,与编译型语言 Java,C++ 有性能差距,怎么提高 PHP 效率?

希望PHP大牛们都来探讨下

回复内容:

facebook告诉我们,PHP要提高效率,最好就是改语法,然后就做出了HHVM 关于这个问题,我其实就是想进来吐个槽
一般来说 最简单的提高效率办法就是在开发中注意很多php的效率优化技巧。比如算法、语法、架构等。这些在经验和网上都能积累到很多方法。
如果你发现,效率的瓶颈不在这些无所谓的东西上。有些功能就慢在一些函数和功能上、那OK,哪里有问题就去解决哪里,用C扩展的方式解决。但是这样就有很多连带问题比如业务逻辑往往要因C扩展的方式而可能发生改变。
或者你发现,本身PHP这种解释性语言就是慢,哪里都慢(笑),怎么破。这就有了加速器,用缓存操作码的方式来避免再次解析 一些相关介绍和讲解题主可以简单看看这里
三款免费的PHP加速器:APC、eAccelerator、XCache比较
或者我们换一种思路,直接换成二进制语言执行会不会更快呢。题注可以看看 如下几种解决方案。c(Roadsend和phc)、c++(hiphop)、java(Quercus)、c#(Phalanger)。不过以hipop举例,这货
facebook/hhvm · GitHub 。是facebook的hhvm的前身,他其实就是将php转化为高度优化的C++代码然后用g++编译,还有一些其他的如code transformer。通过这些方式来从本质上将php变成另一门语言。不过这货部署之坑爹,使用之困难,调试之麻烦,编译时间之长久简直是反人类。

我觉得集上述优点之大成者,hhvm,就这么诞生了。
hhvm其实就是HipHop的改良版,目前稳定版是2.3,性能高于hiphop40%。hhvm.com/
语言表述不清楚,这里就不说嘛zend和hhvm的原理了,我觉得hhvm如果要和zend做对比的话就是在于hhvm如果开启了jit,hhvm就可以直接执行机器码。而zend虽然cache了opcode但是还是要通过调用C去执行机器码。
相关的文档网上有很多,题主可以关注一下

题主也可以看看这个解决方案 HippyVM,据说是专门用来打脸Facebook的
官方声称说是比原生PHP快7.x比脸书的hhvm快2x
贴一个官网看到的图
PHP 作为解释性语言,与编译型语言  Java,C++ 有性能差距,怎么提高 PHP 效率?
具体我也没有测试过
只能说pypy太牛逼了
不知道facebook会不会感觉到被打脸了呢 啪啪啪~( מּ_מּ)

小白一个,如有说错的地方希望各位大神指正。对了,php是世界上最好的语言(笑) phpNG完结此帖 PHPNG 、HHVM、YAF、百度ODP、Swoole 其实说php性能差的,都不知道多少年没有用过php了。像yaf 和phalcon这种c开发的框架,你觉着性能会有多差?另外还在纠结解释型语言的,就完全不知道还有opcache这种东西,现在的php,都是运行一次就自动预编译了。 0. 你已经遇到这个程度的瓶颈了吗?
1. PHP 7,敬请期待…… 把它改造成静态语言! php虽然是generic编程语言,但是99.9%的时候还是用在web开发中,所以瓶颈一般不在php这边,而是出现在网络IO比如db层。
我目前做优化首先会使用xhprof这样的工具进行测量,找出最耗时的部分:绝大多数都在db调用,比如PDO连接数,可以通过优化代码减少。
另外,db层的优化,一般就是加索引,通过分析执行的sql语句(最好有log)和explain,适当的添加组合索引,顺便也利用好覆盖索引。虽然添加索引会影响插入效率,但是写入相对于读取还是很符合28法则的。
最后,随着系统变得复杂,需要通过优化架构来提升性能,比如在db和app之间加上缓存,耗时任务异步化等等。
——————这里面能写的东西太多了,我只是泛泛的谈一谈————————
从php语言的角度来看,开发一般都会使用框架,而框架会带来无法避免的消耗,所以会出现phalcon和yaf这样优秀的通过扩展php写的mvc框架;
php的hhvm是另外的一种提升php性能的方式,比phalcon和yaf这样的框架可能带来的性能更好,但是有点另立门户的赶脚,所以在php社区已经相当成熟的时候,大部分人不会去选择hhvm,风险很大。即使是phalcon这样的c语言写的框架,对于比较小的团队,采用它的风险也比较大,驾驭不了c语言,出了问题很严重的~~ 直接用hhvm吧,Facebook在用,或者换异步的框架。
不过一般PHP应用场景里,性能并不取决于PHP自身。 Swoole: PHP的异步、并行、分布式扩展
有图有真相
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP in Action: Real-World Examples and ApplicationsPHP in Action: Real-World Examples and ApplicationsApr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: Creating Interactive Web Content with EasePHP: Creating Interactive Web Content with EaseApr 14, 2025 am 12:15 AM

PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

PHP and Python: Comparing Two Popular Programming LanguagesPHP and Python: Comparing Two Popular Programming LanguagesApr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

The Enduring Relevance of PHP: Is It Still Alive?The Enduring Relevance of PHP: Is It Still Alive?Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP's Current Status: A Look at Web Development TrendsPHP's Current Status: A Look at Web Development TrendsApr 13, 2025 am 12:20 AM

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP vs. Other Languages: A ComparisonPHP vs. Other Languages: A ComparisonApr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP vs. Python: Core Features and FunctionalityPHP vs. Python: Core Features and FunctionalityApr 13, 2025 am 12:16 AM

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

PHP: A Key Language for Web DevelopmentPHP: A Key Language for Web DevelopmentApr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools