Home php教程 php手册 配置优化让你的PHP引擎全速运转

配置优化让你的PHP引擎全速运转

Jun 13, 2016 am 10:30 AM
php web mainstream optimization develop engine flow now programming language Configuration


  作为流行的 Web 编程语言, php(做为现在的主流开发语言) 的最大优势就是速度。 php(做为现在的主流开发语言)4 已经在这方面做的非常好了,你几乎找不到比它更快的脚本编程语言了。但是如果你的应用负荷很大,而带宽又比较小,或者有其他的瓶颈影响你的服务器性能,那么,你不妨试试笔者为你开出的几个药方,看看是否灵验。
  
  一、代码优化
  一谈到代码优化,或许你想到的就是整齐明了的代码,但是本文的意思却不是在此,因为如果要寻求速度的话,就要对php(做为现在的主流开发语言) 源码作相应的调整。一般说来就是去掉多余的注释,让代码不可读。但是这对于一个具有良好素养的程序员来说,简直就是不可思议的。好在Zend Technologies 公司发布了 Zend 优化引擎可以帮助你做到这一点。它现在是免费的,但是你必须遵循 Zend Optimizer 许可。这个产品可以对引擎产生的中间代码进行优化。
  
  安装这个引擎比较简单,下载对应平台的版本以后,解开压缩文件,然后在 php(做为现在的主流开发语言).ini 文件里面加上下面两行,重新启动 Web 服务器,就搞定了。
  
  zend_optimizer.optimization_level=15
  
  zend_extension="/path/to/ZendOptimizer.so"
  
  zend_loader.enable=Off
  
  如果是 Win32 平台的话就应该是:
  
  zend_optimizer.optimization_level=15
  
  zend_extension_ts="C:path oendOptimizer.dll"
  
  zend_loader.enable=Off
  
  啊!没有搞错吧?怎么是三行?其实第三行是可选的。因为看起来把 zend_loader 关掉能提高一点速度,因此值得把这第三行放到 php(做为现在的主流开发语言).ini 。需要注意的是,关掉的前提条件是你没有在使用 Zend 加密程序。
  
  二、缓冲
  如果想要更进一步提升速度,我们就需要考虑采用缓冲技术了。有一些可选的解决方案,包括 Zend Cache (测试版本), APC, 以及 Afterburner Cache,另外还有 jpCache 等。
  
  以上这些都是属于缓冲模块,他们把第一次对 .php(做为现在的主流开发语言) 文件请求产生的中间代码存储在 Web 服务器的内存中,然后对以后的请求返回“编译好”的版本。因为这样减少了磁盘读写,而且都在内存工作,所以这个过程能显着提升应用性能,
  
  现成的这类产品比较多,到底选择谁呢?
  
  Zend Cache 是一款不错的商业产品,在第一次加载那些很大的 php(做为现在的主流开发语言) 页面后,你会明显感受到速度的提升,服务器会留出更多的资源。可惜这个产品是要花银子的,但是在有些情形下,你可不要吝啬这些银子。
  
  Afterburner Cache 是 Bware Technologies 的产品,目前还处于 Beta 版本,看起来似乎和 Zend Cashe 一样,但是它不能达到 Zend Cache 那样好的效果,也不能和 Zend 优化引擎一起工作,但是它是免费的,所以我采用了这个模块。
  
  APC (Alternative php(做为现在的主流开发语言) Cache) 是 Community Connect 发布的又一个免费模块,看起来似乎可以用于生产环境了。
  
  Web 内容压缩
  对于日益拥挤的网络来说,节约带宽就像节约用水一样是十分值得提倡的。根据IETF 标准,大多数浏览器应该支持使用 gzip 压缩的内容。也就是说你可以把用 gzip 压缩的内容发送给浏览器,浏览器会透明的解压数据。
  
  mod_gzip 是 Remote Communications 公司推出的免费 apache(Unix平台最流行的WEB服务器平台) 模块,能把静态的Web 内容压缩后发送给浏览器。对于大多数静态网页来说,这个模块十分合适。尽管
  
  Remotecommunications 公司的人说这个模块支持所有那些 mod_php(做为现在的主流开发语言), mod_perl,mod 什么产生的动态内容,但是看起来还是不能工作,从 mod_gzip 的邮件列表来看,这个问题估计要到1.3.14.6f 才能解决。
  
  如果要压缩动态内容的话,我们可以采用class.gzip_encode.php(做为现在的主流开发语言),一个在脚本开始和结束时使用的 php(做为现在的主流开发语言) 类。对整个网站来说就是在 php(做为现在的主流开发语言).ini 的 auto_prepend 和 auto_append 中调用其中的函数。详细你可以阅读这个类的程序,这个程序注释得很好,作者几乎把什么都告诉你了。不过使用之前,你的 php(做为现在的主流开发语言) 要编译为支持 zlib。

Statement of this Website
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

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 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.

Demystifying JavaScript: What It Does and Why It Matters Demystifying JavaScript: What It Does and Why It Matters Apr 09, 2025 am 12:07 AM

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 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

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 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.

Explain the match expression (PHP 8 ) and how it differs from switch. Explain the match expression (PHP 8 ) and how it differs from switch. Apr 06, 2025 am 12:03 AM

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.

What is Cross-Site Request Forgery (CSRF) and how do you implement CSRF protection in PHP? What is Cross-Site Request Forgery (CSRF) and how do you implement CSRF protection in PHP? Apr 07, 2025 am 12:02 AM

In PHP, you can effectively prevent CSRF attacks by using unpredictable tokens. Specific methods include: 1. Generate and embed CSRF tokens in the form; 2. Verify the validity of the token when processing the request.

PHP's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

See all articles