Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
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 ". Load bottlenecks are generally in the following four aspects:
2 server CPU
3 Hard disk I/O
4. network bandwidth
Except the four. 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.
If window is used, find this extension 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.
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to email@example.com. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
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:
and provide relevant evidence. A staff member will contact you within 5 working days.