Memcache Client Connection Series (iv) PHP

Source: Internet
Author: User
Tags install php php memcached



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.


  1. Install gcc-c++ and make and other compiled components.

    Yum Install gcc-c++ make

  2. Install SASL related packages.

    Yum Install cyrus-sasl*

  3. 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.

  4. Install PHP.

    Yum Install Php-devel Php-common php-cli

  5. 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

  6. The
  7. 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 
     


  8. 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:


  1. Install the compilation components such as GCC and make.

    Apt Install gcc make

  2. 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 ' "" '

  3. Install the SASL component.

    Apt Install Libsasl2-dev cloog.ppl

  4. 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.

  5. 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;

  6. The
  7. 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 
     


  8. 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


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.