Keywords: Memcached PHP client
Disclaimer: This article is not original and is transferred from the Cloud Help Center's distributed cache Service (DCS) User Guide. Client Connection method is universal, so excerpt to share to everyone.
PHP Client
Redhat Series:
Take CentOS7 as an example to introduce the installation of PHP version client. Redhat, fedora and other systems are also available.
-
- Install gcc-c++ and make and other compiled components.
Yum Install gcc-c++ make
-
- Install SASL related packages.
Yum Install cyrus-sasl*
-
- Install libmemcached.
Because the Libmemcached library requires additional SASL authentication parameters, it cannot be installed directly using the Yum command.
wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
TAR-XVF libmemcached-1.0.18.tar.gz
CD libmemcached-1.0.18
./configure--prefix=/usr/local/libmemcached--ENABLE-SASL
Make && make install
Description Complete installation of gcc-c++, SASL related components before installing libmemcached. Otherwise, the error will be in the compilation process, the error after the problem is resolved please do clean after the re-make.
-
- Install PHP.
Yum Install Php-devel Php-common php-cli
-
- Install the memcached client.
Note When you run the Configure configuration installation, the open SASL parameter is added.
wget http://pecl.php.net/get/memcached-2.1.0.tgz
Tar zxvf memcached-2.1.0.tgz
CD memcached-2.1.0
Phpize
./configure--with-libmemcached-dir=/usr/local/libmemcached--ENABLE-MEMCACHED-SASL
Make && make install
- The
- increases the php.ini configuration.
Use the Find or locate command to locate the php.ini file.
Find/-name php.ini
To edit the file, add the following two lines:
extension= MEMCACHED.SOMEMCACHED.USE_SASL = 1
-
- Test the connection.
Add a new memcached.php file that adds the following:
<?php $connect = new Memcached;//Declare a Memcached connection $connect->setoption (memcached::opt_compression, FALSE); Turn off compression $connect->setoption (Memcached::opt_binary_protocol, true);//Use binary protocol $connect->setoption ( Memcached::opt_tcp_nodelay, True); Close the TCP network latency policy $connect->addserver (' {memcached_instance_ip} ', 11211);//Fill in the instance IP and port $connect Setsaslauthdata (' {username} ', ' {password} '); If the instance turns on no-secret access, delete or annotate this line $connect->set ("DCS", "Come on!"); Echo ' DCS: ', $connect->get ("DCs"); echo "\ n"; $connect->quit ();? >
After saving, the following conditions are run:
[[email protected] ~]# PHP memcached.php
Debian series
In Ubuntu, for example, the installation steps are as follows:
-
- Install the compilation components such as GCC and make.
Apt Install gcc make
-
- Install PHP.
It is recommended to use php5.x version, which is good for SASL authentication.
Follow these steps to add a lower version of the image source for PHP, and then install php5.6 and Php5.6-dev.
Apt-get install-y language-pack-en-base;
Lc_all=en_us. UTF-8;
Add-apt-repository ppa:ondrej/php;
Apt-get Update;
Apt-get install php5.6 Php5.6-dev;
After the installation is complete, use Php-version to view the version number 5.6, which indicates that the installation was successful.
[Email protected]:/etc/apt# php-versionphp 5.6.36-1+ubuntu16.04.1+deb.sury.org+1 (CLI) Copyright (c) 1997-2016 the PHP G Roup
Description: If you need to uninstall PHP, you can use the following command:
Apt Install aptitude-y
Aptitude Purge ' dpkg-l | grep php| awk ' {print $} ' |tr ' \ n ' "" '
-
- Install the SASL component.
Apt Install Libsasl2-dev cloog.ppl
-
- Install libmemcached.
wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
TAR-XVF libmemcached-1.0.18.tar.gz
CD libmemcached-1.0.18
./configure--prefix=/usr/local/libmemcached
Make && make install
Description Complete the installation of GCC, SASL related components before installing libmemcached. Otherwise, the error will be in the compilation process, the error after the problem is resolved please do clean after the re-make.
-
- Install the memcached client.
Install the Zlib component first.
Apt Install Zlib1g.dev
Installation Note When you run the Configure configuration installation, the SASL parameter is added.
Wget http://pecl.php.net/get/memcached-2.2.0.tgz;
Tar zxvf memcached-2.2.0.tgz;
CD memcached-2.2.0;
phpize5.6;
./configure--with-libmemcached-dir=/usr/local/libmemcached--ENABLE-MEMCACHED-SASL;
Make && make install;
- The
- increases the Pdo.ini configuration. The
uses the Find command to locate the Pdo.ini file.
Find/-name Pdo.ini
Should be in the/etc/php/5.6/mods-available path by default. To edit the file, add the following two lines:
EXTENSION=MEMCACHED.SOMEMCACHED.USE_SASL = 1
-
- Test the connection.
Add a new memcached.php file that adds the following:
<?php $connect = new Memcached;//Declare a Memcached connection $connect->setoption (memcached::opt_compression, FALSE); Turn off compression $connect->setoption (Memcached::opt_binary_protocol, true);//Use binary protocol $connect->setoption ( Memcached::opt_tcp_nodelay, True); Close the TCP network latency policy $connect->addserver (' {memcached_instance_ip} ', 11211);//Fill in the instance IP and port $connect Setsaslauthdata (' {username} ', ' {password} '); If the instance turns on no-secret access, delete or annotate this line $connect->set ("DCS", "Come on!"); Echo ' DCS: ', $connect->get ("DCs"); echo "\ n"; $connect->quit ();? >
After saving, the following conditions are run:
[[email protected] ~]# PHP memcached.php
Memcache Client Connection Series (iv) PHP