Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to adjust the performance of PHP

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to adjust the performance of PHP". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's ideas to study and learn "how to adjust the performance of PHP".

Generally speaking, load bottlenecks are mainly in the following four aspects:

1 database

2 Server CPU

3 hard disk IPUBO

4 network bandwidth

Except for these four. What else is there to optimize. Php is really strong. Today, let's talk about adjusting the performance of PHP at the script level of PHP.

If you want to improve the performance of PHP on a single server. We can use the compile cache. Compiling cache not only improves performance, but also increases server performance as the capacity and code complexity of PHP programs increase. What is compiling cache? I'll tell you later. Let's first talk about the two steps that PHP takes to compile a script file:

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

2 ZEND starts executing intermediate code for the second time

We should pay attention. The first step is to repeat something every time the PHP script file is requested. And this process repeats the first step recursively because the script also includes include () require () eval (). You can imagine how much it consumes. Especially when the PHP file is very large. So why do you disapprove of having too many lines when writing a PHP file?

At this point, everyone will understand. In fact, we can do some articles in the first step. If we cache the interpreted code into shared memory in the first step of the explanation file. If you have a second request for this script, you can skip the first step and go straight to the second step. Because the first step is already cache in memory.

Let's look at the picture and compare it.

Let's take a look at the situation if compiling cache is not used.

Another case in which compiled cache is used.

All right, you'll see. It is, isn't it? With compiling cache, it takes a lot of detours. It is especially effective when there are a lot of include and require in your code.

Now let's introduce three compiled cache:

1 The ionCube Accelerator is not open source.

2 TheZendAccelerator asks for money. I'm poor.

3 APC I like this best because it's free. The effect is pretty good.

Let's just say APC.

The installation looks something like this. Install via pear

# pear install apc

Modify php.ini and add extension

Extension = / path/to/apc.so

OK is as simple as that. But when you run PHP again. This APC has already worked. The compiled code is cache in share memory. That's awesome.

If it's window, look for this extension in it.

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

Thank you for your reading, the above is the content of "how to adjust the performance of PHP", after the study of this article, I believe you have a deeper understanding of how to adjust the performance of PHP, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report