PHP's language-level optimization and code optimization _php Tutorial

Source: Internet
Author: User
Tags apc pear ioncube

In large-scale system development, the cache is undoubtedly crucial, PHP world, although not as Java, there are so many cache solution can choose, but there are still some mature solutions, from "Advanced PHP Programming" I learned some of the following:

1, the language level of optimization: PHP has a lot of engine-level API, through these APIs, can change the behavior of the engine execution, so as to achieve optimal operation. One of the most worthwhile things to do is cache the results of the compilation. As we all know, PHP every execution needs to go through the source code –〉 compiled –〉 intermediate code –〉 engine to do such a process, for some large applications, a considerable amount of time spent on useless compilation (not just the PHP file to access the page needs to be compiled, when the script uses require (), Some of the files included in the include () need to be compiled. By caching the results of the compilation, the performance of the system can be greatly improved (proportional to the complexity and scale of the system).

The three main tools in the PHP world that are capable of compiling the cache are:

The Zend accelerator-a Commercial, Closed-source, For-cost compiler cache produced by Zend Industries
The Ioncube accelerator-a Commercial, Closed-source, but free compiler cache written by Nick Lindridge and distributed by His company, Ioncube
Apc-a free and Open-source compiler caches written by Daniel Cowgill and George Schlossnagle

APC installation method, APC included in the PECL, the specific installation of the following 190-823 190-802:

Run command

#pear Install APC

After that, add the following in the php.ini file:

Extension =/path/to/apc.so

This completes the installation, when the next run PHP,APC will be automatically activated, the results of the compilation into the shared memory cache, the next time you execute it directly from memory to get the results of the execution, do not need to compile again.

Question: Will the PHP,APC be automatically recompiled for changes since the last compilation?

2, PHP code optimization: The use of some tools to compile the city after the production of high-quality intermediate code, specifically as follows:

The Zend Optimizer is a closed-source but freely available Optimizer.
The Ioncube accelerator contains an integrated optimizer.
Proof-of-concept Optimizer in PEAR.

Key features of the optimizer:

1. Clean up useless code, such as dead code that will never execute.

2, the calculation of constants, for example, $seconds_in_day = 24*60*60 directly into $seconds_in_day = 86400;

3, other code optimization functions, such as a statement:

$count + +;

will be optimized for + + $count, making execution faster. Of course, if the statement is $i = $count + +, it will not be optimized

http://www.bkjia.com/PHPjc/508244.html www.bkjia.com true http://www.bkjia.com/PHPjc/508244.html techarticle in large-scale system development, the cache is undoubtedly crucial, in the PHP world, although not as good as Java, there are so rich cache solution can choose, but still some mature ...

  • 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.