Use Xcache to accelerate your PHP Site

Source: Internet
Author: User
Tags apc varnish
Because the domestic website ICP filing is troublesome, the author places the website in Hong Kong. Although the website is not subject to record filing, the access speed is generally 2-3 times slower than that of websites in China. Therefore, we have made some simple improvements to the website, for example, the cache system is used to speed up website page access. Currently used for w

Because the domestic website ICP filing is troublesome, the author places the website in Hong Kong. Although the website is not subject to record filing, the access speed is generally 2-3 times slower than that of websites in China. Therefore, we have made some simple improvements to the website, for example, the cache system is used to speed up website page access.

Currently, many web cache systems are used, including squid, varnish, proxy_cache provided by Nginx, fastcgi_cache, APC, and Xcache in FastCGI. Systems such as squid, varnish, and Nginx's proxy_cache are heavyweight products. configuration and maintenance are troublesome and are not suitable for small websites. In addition, these systems are generally used to cache static content, such as fastcgi_cache in FastCGI, which is mainly used to cache dynamic content. Therefore, it is extremely fast to access websites using fastcgi_cache, however, when I use it, I find it difficult to maintain it. In particular, after each website has data to be updated, if you need to manually clear the cache after the expiration of the buffer period to see the updated content of the website; as for APC, I personally feel that the performance is normal. when comparing it with Xcache, I found that the speed of accessing the Xcache website is significantly higher than that of using the APC website (I have not specifically tested it ), therefore, Xcache is selected.

We all know that PHP is a dynamic language that is executed in an interpreted manner. Therefore, every execution of PHP code is parsed and converted into an opcode ). Xcache is an open-source operation code cache/optimizer. it caches the parsed/converted PHP operation code to a file (until the original code is modified) to avoid repeated parsing processes, the code execution speed is improved. Generally, the page generation rate is increased by 2-5 times, server load is reduced, and the website access speed is improved.


1. install Xcache


# Wget http://xcache.lighttpd.net/pub/Releases/1.3.0/xcache-1.3.0.tar.gz

# Tar zxvf xcache-1.3.0.tar.gz

# Cd xcache-1.3.0

#/Usr/local/php/bin/phpize

#./Configure? Enable-xcache? Enable-xcache-coverager? Enable-xcache-optimizer? With-php-config =/usr/local/php/bin/php-config

# Make & make install

Note :? Enable-xcache indicates that Xcache support is enabled ;? Enable-xcache-coverager indicates additional features used to measure accelerator efficacy ;? Enable-xcache-optimizer indicates that the operation code optimization is enabled.

After the installation is complete, the system prompts xcache. so module generated path, this generated path for/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/, and then xcache. so move to the/usr/local/php/include/php/ext directory.


II. configure and manage Xcache


1. modify the php configuration file

During configuration, refer to the xcache configuration template xcache. ini, which is located in the Xcache installer.

# Vi/usr/local/php/lib/php. ini and add the following content:
Extension_dir =/usr/local/php/include/php/ext
[Xcache-common]
Extension = xcache. so
[Xcache. admin]
Xcache. admin. enable_auth = On
Xcache. admin. user = "xcache"
Xcache. admin. pass = ""
[Xcache]
Xcache. shm_scheme = "mmap"
Xcache. size = 60 M
Xcache. count = 1
Xcache. slots = 8 K
Xcache. ttl = 0
Xcache. gc_interval = 0
Xcache. var_size = 4 M
Xcache. var_count = 1
Xcache. var_slots = 8 K
Xcache. var_ttl = 0
Xcache. var_maxttl = 0
Xcache. var_gc_interval = 300
Xcache. test = Off
Xcache. readonly_protection = On
Xcache. mmap_path = "/tmp/xcache"
Xcache. coredump_directory = ""
Xcache. cacher = On
Xcache. stat = On
Xcache. optimizer = Off
[Xcache. coverager]
Xcache. coverager = On
Xcache. coveragedump_directory = ""



2. generate Xcache cache files

# Touch/tmp/xcache

# Chmod 777/tmp/xcache



3. Generate the Xcache administrator secret (MD5 ciphertext)

# Echo-n" 123456 "| md5sum

E10adc3949ba59abbe56e057f20f883e

Then paste the generated MD5 ciphertext into the php. ini file xcache. admin. pass = "" option, xcache. admin. pass = "e10adc3949ba59abbe56e057f20f883e"



4. copy the Xcache hypervisor to the root directory of the website.

# Cp-a/tmp/xcache-1.3.0/admin // usr/local/nginx/html/

Then restart PHP, then access the http://www.2cto.com/admin, the user name is xcache password is 123456; in addition, you can also verify PHP support Xcache through phpinfo.
 

Related Article

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.