View PHP compilation Cache

Source: Internet
Author: User
Tags apc
Load neck is generally mainly in the following four aspects: 1 & nbsp; Database 2 server CPU3 hard disk IO4 network bandwidth in addition to these four things. What else is worth optimization. Php is really strong. Today, let's talk about how to adjust the PHP performance at the PHP script level. If you want to improve PHP performance on a single server. We can use "compile cache ". Compilation of cache not only improves performance, but also increases the performance of PHP programs in terms of capacity and code complexity:
1 Database

2 server CPU

3 Hard disk I/O

4. network bandwidth

Except these four things. What else is worth optimization. Php is really strong. Today, let's talk about how to adjust the PHP performance at the PHP script level.
If you want to improve PHP performance on a single server. We can use "compile cache ". Compiling cache not only improves performance, but also increases server performance with the increase of PHP program capacity and code complexity. What is compile cache. Wait. Let's talk about the two steps to compile the script file in PHP:

1. the php engine reads the script file, interprets the script, and generates executable intermediate code in the ZEND Engine.

2 ZEND starts executing intermediate code for the second time

We should pay attention to it. The first step is to repeat things every time a PHP script file is requested. In addition, this process repeats the first step of recursive execution because the script contains include () require () eval. You can imagine how much it will consume. Especially when php files are large. Therefore, it is recommended that the number of rows in the PHP file be too large.
You will understand it here. In fact, we can make some articles in step 1. If we cache the interpreted code in the first interpretation file to the shared memory. If there is a second request for this script, you can skip the first step and directly go to the second step. Because the first step is already in the memory.
Let's take a look at the figure and compare it.

First, let's take a look at the situation where the compiled cache is not used.

The compilation cache is used again.

You can see it. Right. With the compilation of cache, it takes a lot of detours. This is especially effective when your code contains a large number of include and require statements.

Now we will introduce three compilation caches:
1 The ionCube Accelerator is not open source.
2 TheZendAccelerator. Poor
3. APC: I like it most because I don't need money. The results are quite good.
Let's talk about APC.
The installation is probably like this. Use pear to install
# Pear install apc
Modify php. ini and add extension
Extension =/path/to/apc. so

OK is that simple. But when you run PHP again. This APC has already worked. The compiled code is cached in the share memory. That's cool. Better than a woman.

If it's window, find this extension http://pecl4win.php.net/list.php in it.

After APC is installed, we need to adjust the parameters of APC. Of course, this is adjusted according to your own project environment.

APC has several parameters. Go to Baidu.

Finished.

It's not over yet. Please follow my blog www.laoniphp.com

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.