Home  >  Article  >  Backend Development  >  Install APC (Alternative PHP Cache) to improve PHP parsing speed

Install APC (Alternative PHP Cache) to improve PHP parsing speed

WBOY
WBOYOriginal
2016-08-08 09:31:31836browse

This article quotes "High-Performance PHP Development" for the record

When executing a PHP script from the command line or from a web server, PHP must perform the required 5 steps.


The Zend engine must read the file from the file system, scan its dictionary and expressions, parse the file, create computer code to be executed (called an Opcode), and finally execute the Opcode.

PHP’s life cycle is very short, but every time a request is made to the script, it must perform these 5 steps. Every time a request arrives for a specific PHP script, the Zend Engine must re-create the Opcode for that file, even if the content of the PHP script has not changed. This is necessary for the initial request of the script, but not for subsequent requests. If Opcode caching is implemented, three steps can be omitted to shorten the life cycle of PHP

1) Dictionary parsing;

2) Parsing;

3) Creating Opcode


APC can implement PHP scripts Opcode cache, but APC cannot be turned on during the development stage. Otherwise, if the script is modified, the Zend engine will still execute the Opcode in the cache.

PECL APC address: http://pecl.php.net/package/apc

Install APC, taking CentOS6.5 64-bit as an example

wget http://pecl.php.net/get/APC-3.1.9.tgz #下载
tar zxvf APC-3.1.9.tgz  #解压
cd APC-3.1.9   #切换目录
phpize   #调出 configure 配置文件
./configure --with-php-config=/usr/local/php/bin/php-config  #配置
make && make install #编译安装

Generate apc.so after success

Open php.ini and add

extension=apc.so
apc.enabled=1
apc.shm_segments=1
apc.shm_size=128
apc.stat=0
apc.ttl=0

Save and restart Apache/Nginx.

Attached are the commonly used setting parameters of APC, let’s take a look~


The above introduces the installation of APC (Alternative PHP Cache) to improve the parsing speed of PHP, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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