Install PHP extension Memcache in Linux

Source: Internet
Author: User

Install PHP extension Memcache in Linux

The work of memcache is to maintain a huge hash table in the memory of a dedicated machine to store frequently read and written arrays and files, thus greatly improving the website operation efficiency, reduces the read/write pressure on the backend database.

Lab environment: CentOS 6.6 x86_64
Build the LAMP environment: php version 5.6.8 and apache version 2.4.12
1. Install libevent support before installing memcached:
# Wget http://syslab.comsenz.com/downloads/linux/libevent-1.4.12-stable.tar.gz
# Tar zxvf libevent-1.4.12-stable.tar.gz
# Cd libevent-1.4.12-stable
#./Configure -- prefix =/usr/local/libevent
# Make & make install

2. Compile and install memcached on the server
# Wget http://syslab.comsenz.com/downloads/linux/memcached-1.4.5.tar.gz
# Tar zxvf memcached-1.4.5.tar.gz
# Cd memcached-1.4.5
#./Configure -- prefix =/usr/local/memcached -- with-libevent =/usr/local/libevent/
# Make & make install

3. Steps for installing memcache on the client:
# Wget http://www.lishiming.net/data/attachment/forum/memcache-2.2.3.tgz
# Tar zxvf memcache-2.2.3.tgz
# Cd memcache-2.2.3
#/Usr/local/php/bin/phpize
#./Configure -- with-php-config =/usr/local/php/bin/php-config -- enable-memcache
# Make

The following error is reported after make is executed:
/Usr/local/src/memcache-2.2.3/memcache. c: In the function 'php _ mmc_connect:
/Usr/local/src/memcache-2.2.3/memcache. c: 1902: Error: Too few arguments are provided to the function 'zend _ list_insert'
/Usr/local/src/memcache-2.2.3/memcache. c: 1919: Error: Too few arguments are provided to the function 'zend _ list_insert'
/Usr/local/src/memcache-2.2.3/memcache. c: In the function 'zif _ memcache_add_server:
/Usr/local/src/memcache-2.2.3/memcache. c: 1975: Error: Too few arguments are provided to the function 'zend _ is_callable'
/Usr/local/src/memcache-2.2.3/memcache. c: 2003: Error: Too few arguments are provided to the function 'zend _ list_insert'
/Usr/local/src/memcache-2.2.3/memcache. c: In the 'zif _ memcache_set_server_params 'function:
/Usr/local/src/memcache-2.2.3/memcache. c: 2059: Error: Too few arguments are provided to the function 'zend _ is_callable'
/Usr/local/src/memcache-2.2.3/memcache. c: In the function 'mmc _ find_persistent:
/Usr/local/src/memcache-2.2.3/memcache. c: 2159: Error: Too few arguments are provided to the function 'zend _ list_insert'
/Usr/local/src/memcache-2.2.3/memcache. c: 2177: Error: Too few arguments are provided to the function 'zend _ list_insert'
Make: *** [memcache. lo] Error 1

Modify according to the error:
Vi memcache. c
Put all: zend_list_insert (pool, le_memcache_pool );
Change to: zend_list_insert (pool, le_memcache_pool TSRMLS_CC );

Put all: zend_list_insert (mmc, le_pmemcache );

Changed to: zend_list_insert (mmc, le_pmemcache TSRMLS_CC );
ALL: if (! Zend_is_callable (failure_callback, 0, NULL ))
Changed to: if (! Zend_is_callable (failure_callback, 0, NULL, NULL ))

After the modification is complete, re-make the compilation;
# Make install
Installing shared extensions:/usr/local/php/lib/php/extensions/no-debug-zts-20131226/

The memcache. so module after installation is in the above path;
# Vi/usr/local/php/etc/php. ini
Add extension = "memcache. so" in the last line"
After saving and exiting, restart apache, use php-m to view the installed memcache module, or access phpinfo. php in a browser to view it;

Start memcached Server:
#/Usr/local/memcached/bin/memcached-d-u root-m 256-p 11211-l localhost
-D is to start a daemon process,
-M: Specifies the memory used by memecached. The unit is M.
-P specifies the memcached startup Port
-L specify the bound IP Address
-U indicates to start as an account
An error is reported after startup. The libevent module cannot be found;
/Usr/local/memcached/bin/memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory
The libevent-1.4.so.2 needs to be copied or linked to/usr/lib64 (x86_64-bit system, 32-bit/usr/lib directory), otherwise memcached cannot load normally.
# Cp/usr/local/libevent/lib/libevent-1.4.so.2/usr/lib64


Test the memcache environment and write a PHP file under the root directory of the website.
[Root @ localhost htdocs] # cat 1.php
<? Php
$ Mem = new Memcache;
$ Mem-> connect ("localhost", 11211 );
$ Mem-> set ('test', 'Hello world', 0, 60 );
Echo $ mem-> get ('test ');
?>

Use curl or webpage access IP Address/1. If php displays hello world, the configuration is successful.
# Curl-xlocalhost: 80 192.168.4.231/1.php
Hello world

Memcached installation and startup script

Performance problems of using Memcached in PHP

Install Memcached in Ubuntu and its command explanation

Install and apply Memcached

Use Nginx + Memcached's small image storage solution

Getting started with Memcached

For details about Memcached, click here
Memcached: click here

This article permanently updates the link address:

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.