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

Php service cache acceleration

2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

PHP service accelerates cache optimization

PHP caching principle:

When the client requests a PHP program, the server's PHP engine parses the PHP program and compiles it into a specific opcode (Operate Code referred to as opcode)

The modification file is a binary representation after the execution of PHP code. By default, the compiled opcode file is discarded after execution by the PHP engine. And the principle of opcode caching:

Save the compiled opcode and put it in shared memory for reuse the next time you call PHP. (save compilation time of PHP engine)

The principle of PHP cache accelerator in LA (N) MP environment:

1) apache (nginx) receives the PHP program access request from the client.

2) apache (nginx) passes the program to the PHP processing module libphp5.so (php's FCGI--php-fpm) process.

3) the PHP engine (php-fpm process) reads the PHP file on disk and loads the device into memory for parsing.

4) PHP processing module libphp5.so (php parser php.ini) compiles the PHP source code into cpdode and caches cpcode.

5) after apache (nginx) receives the request from the client, the PHP engine reads the opcode file directly. Repeat steps 1-4 if it is not found. Establish a cache.

Additional knowledge:

The language environment in which locale computer software runs:

# locale

LANG=en_US.UTF-8

LC_CTYPE= "en_US.UTF-8"

LC_NUMERIC= "en_US.UTF-8"

LC_TIME= "en_US.UTF-8"

LC_COLLATE= "en_US.UTF-8"

LC_MONETARY= "en_US.UTF-8"

LC_MESSAGES= "en_US.UTF-8"

LC_PAPER= "en_US.UTF-8"

LC_NAME= "en_US.UTF-8"

LC_ADDRESS= "en_US.UTF-8"

LC_TELEPHONE= "en_US.UTF-8"

LC_MEASUREMENT= "en_US.UTF-8"

LC_IDENTIFICATION= "en_US.UTF-8"

LC_ALL=

According to the various aspects of usage habits involved, locale divides them into 12 categories, which are:

Language symbols and their Classification (LC_CTYPE)

Digital (LC_NUMBERIC)

Get used to it (LC_COLLATE)

Time display format (LC_TIME)

Monetary unit (LC_MONETARY)

The information is mainly prompt message, error message, status message, title, label, button and menu (LC_MESSAGES).

OK? writing mode (LC_NAME)

Address Writing method (LC_ADDRESS)

Telephone number Writing method (LC_TELEPHONE)

Expression of weights and measures (LC_MEASUREMENT)

Default Paper size (LC_PAPER)

An overview of the information contained in locale itself (LC_IDENTIFICATION)

The configuration of this information is usually placed in the / usr/share/i18n/locales directory.

Part of the software requirements Perl. In order to solve some environmental problems of Perl, it brings errors. It can be avoided by modifying environment variables.

# echo 'export LC_ALL=C' > > / etc/profile

# tail-1 / etc/profile

# source / etc/profile

Install the Perl-related software dependency package # yum install perl-devel or # yum install perl-CPAN

Install the PHP XCache cache acceleration module

X Cache caches the compiled data (opcode) of the PHP program into shared memory to avoid repeated compilation of the same program.

When users request the same PHP program, they can directly use the compiled data in the cache to improve the access speed.

# wget https://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.bz2-- no-check-certificate

# tar jxvf xcache-3.2.0.tar.bz2

# / application/php/bin/phpize

Phpize function: used to expand the PHP expansion module, through the phpize can be established PHP plug-in module.

Provide the necessary tools for software package platform environment analysis, compilation and installation.

#. / configure-enable-xcache-with-php-config=/application/php/bin/php-config

# make

# make install

# ll / application/php5.5.38/lib/php/extensions/no-debug-non-zts-20121212/

See if it contains xcache.so to indicate that the installation is complete.

Install database cache and other PHP extensions

Memcached caching software: mem memory cache cache. D means daemon (server-side process mode service)

Memcached is divided into two parts: server side (memcached) and client side (memcache)

General scenario: the data is stored in the database, and when web accesses it, you have to access the database constantly. Benefits of joining memcached: caching in your own memory

The query results of the database can reduce the number of visits to the database, and the efficiency of accessing memory is higher than that of accessing hard disk.

The working steps of memcached's service:

1. First check whether it exists in the cache of the memcached service. If there is, return the request data directly

There is no data in 2.memcached. Access the database.

3. The database takes the data and returns it to the client.

4. At the same time, a copy of the newly fetched data cache is given to the memcached service cache. Stand by.

Memcache client PHP extension (memcache2.2.7.tgz)

# wget http://pecl.php.net/get/memcache-2.2.7.tgz

#. / configure-enable-memcache-with-php-config=/application/php/bin/php-config

# make

# make install

# ll / application/php5.5.38/lib/php/extensions/no-debug-non-zts-20121212/

Does it include memcache.so?

Installation: PDO_MYSQL expansion module

Download address: # wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz

Generally, when compiling PHP, add this module as a parameter:-- with-pdo-mysql=mysqlnd

If the source package compilation and installation is the same as the previous installation (skimming steps)

The platform analysis is as follows:

#. / configure-with-php-config=/application/php/bin/php-config-with-pdo-mysql-mysql=/application/mysql

Install image processing program and imagick extension module

Install the image software: ImageMagick

Install the imagick module

# wget http://pecl.php.net/get/imagick-3.4.3.tgz

# / application/php/bin/phpize

#. / configure-with-php-config=/application/php/bin/php-config

Configuration module takes effect: modify php.ini file. Change the address of the loading module.

Extension_dir = "/ application/php/lib/php/extensions/no-debug-non-zts-20121212"

Extension=memcache.so

Extension=imagick.so

Configure XCache plug-in acceleration

1. First modify the configuration file xcache.ini that comes with xcache, and then add the modified file to the end of the php.ini (engine file) file

# grep-vE "^; | ^ $" / data/xcache-3.2.0/xcache.ini > xcache.ini.bak

The main modifications are as follows:

Xcache.size = 256m

Xcache.count = 2

Xcache.ttl = 86400

Xcache.gc_interval = 3600

Xcache.var_size = 64m

* * xcache.size non-0 means caching is enabled. The following values represent the maximum allowed mmap (a memory sharing mechanism)

Number of xcache.count official recommendation servers CPU # grep-c processor / proc/cpuinfo (number of matching CPU)

Xcache.ttl ttl (time to live) sets the lifetime of cache objects

The time interval at which the xcache.gc_interval collector scans expired objects to reclaim memory space (if set to 0. 0. Do not recycle, and reclamation must be enabled to start the cache)

Caching of xcache.var_size variables

# cat xcache.ini.bak > > / application/php/lib/php.ini

Because XCache uses shared memory as storage space, you can adjust the shared memory size parameter if necessary.

# tail / etc/sysctl.conf

Kernel.msgmnb = 65536

# Controls the maximum size of a message, in bytes

Kernel.msgmax = 65536

# Controls the maximum shared segment size, in bytes

Kernel.shmmax = 68719476736

# Controls the maximum number of shared memory segments, in pages

Kernel.shmall = 4294967296

two。 Restart PHP to check the xcache load

# pkill php-fpm

# / application/php/sbin/php-fpm

# / application/php/bin/php-v

PHP 5.5.38 (cli) (built: Feb 1 2017 22:43:58)

Copyright (c) 1997-2015 The PHP Group

Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies

With XCache v3.2.0, Copyright (c) 2005-2014, by mOo

With XCache Cacher v3.2.0, Copyright (c) 2005-2014, by mOo

3. Configure the web interface to view xcache cache acceleration information.

Modify the

Xcache.admin.user = "mOo" # replace mOo

Xcache.admin.pass = "md5 encrypted password"

# here is the use of md5 algorithm to generate encrypted strings

For example:

# echo-n '123456' | md5sum

E10adc3949ba59abbe56e057f20f883e-

Replace the content with e10adc3949ba59abbe56e057f20f883e

Reference pages related to xcache

# cd / data/xcache-3.2.0

# cp-a. / htdocs/ / application/nginx/html/blog/xadmin

# chown-R nginx.nginx / application/nginx/html/blog/xadmin

# pkill php-fpm

# / application/php/sbin/php-fpm

The following is attached: pressure test effect comparison: (yesterday is the data that did not join xcache cache, the right side is adding xcache cache effect)

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

Database

Wechat

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

12
Report