Home php教程 php手册 解决php加载慢的一个办法

解决php加载慢的一个办法

Jun 13, 2016 am 10:46 AM
php Method load Discover exist slow us document hour time frame test of at present solve

这几天在测试我们目前的php框架时发现,框架层加载php文件的时间很长,最终发现是因为各种require_once导致整个加载时间变长,如果不使用eaccelerator的情况下,在虚拟机上测试可能会到50-60ms,使用了ea之后,可以降到10-20ms,但是这个消耗还是比较大的,有什么办法可以解决吗?

正好这两天看到hiphop的文章,所以决定使用它来试一下,最终发现代价太大了,修改一个文件要把整个工程全部编译一次,并且它生成的程序是http协议的,我们现在只是需要一个fastcgi服务器就行了,而且自己写的各种扩展完全无法使用了,所以这条路基本上否定了。

虽然hiphop这条路走不通,但是却给我一个启示,既然造成加载慢的原因是require_once导致的,那干脆写个脚本,把目前的所有代码都merge成一个大的文件不就行了(因为我们的框架是rpc的,因此只有一个入口,index.php,其他的代码里全是class和function,不存在直接的调用逻辑,因此merge以后不会有任何影响)。具体的操作如下:

1、将所有的require_once行删除,换成|空行

2、将文件开头的

3、记录每个文件在merge后的文件里的offset,将这个信息输出在merge后的文件尾,这个是用于修正日志的,因为merge完了之后,日志打印出来的信息都是那个merge完的文件以及行数,这对于线下查日志没有任何帮助,因此需要修改日志输出类,根据merge后的行数对日志进行修正。

做完之后,实际测了一下,发现如果不使用ea的话,框架的消耗基本在3-5ms,如果使用了ea,反而在5-6ms,去看了一下ea的代码,发现原来它是将解析出来的op_array经过分类存储,然后每次调用zend_compile时,再把这些东西重新拷贝再返回,这个过程并不比zend_compile实际去编译快,而且还有许多额外的检查,因此反而不如直接使用php-cgi。

 

另外在测试时发现php一个很奇怪的现象

class A extends B

{

}

 

class B{}

这段代码是可以的,

 

但是

class A extend B{}

class B extend C{}

class C{}

这样的代码就会出错了www.2cto.com

 

注:后来又测了一下autoload方式,发现比打成一个文件慢很多,在只自动加载一两个类的情况下,某个特定请求需要执行20ms左右,而打成一个只需要5ms左右

摘自 无心云

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

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)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

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 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

See all articles