最新消息:觉得本站不错的话 记得收藏哦 博客内某些功能仅供测试 讨论群:135931704 快养不起小站了 各位有闲钱就打赏下把 My Email weicots#gmail.com Please replace # with @

CentOS 7* PHP memcache 和 memcached 扩展 以及其他扩展

LINX ajiang-tuzi 17961浏览

安装

1.在系统中添加 repo

rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
//其他包含  php56w-pecl-memcached 源:
RedHat EL 6 	repo.webtatic.com/yum/el6/x86_64/php56w-pecl-memcached-2.2.0-2.w6.x86_64.rpm
RedHat EL 6 	repo.webtatic.com/yum/el6/i386/php56w-pecl-memcached-2.2.0-2.w6.i386.rpm
RedHat EL 7 	repo.webtatic.com/yum/el7/x86_64/RPMS/php56w-pecl-memcached-2.2.0-1.w7.x86_64.rpm

2.安装
php 5.5X 安装方法

yum -y update
yum install -y libevent libevent-devel
yum install -y memcached
yum install -y php-pecl-memcache

php 5.6x 安装方法

yum install -y php56w-pecl-memcache. 
使用 yum 搜索检查
yum search memcache|grep php 

安装 php 5.6 opencache

yum install php56w php56w-opcache

安装 php-intl php 5.3x -5.5x

yum --enablerepo=remi install php-intl

php 5.6x

yum --enablerepo=remi,remi-php56 install php-intl

memcached 配置和测试

  1. Change the memcached configuration setting for CACHESIZE and OPTIONS:
    1. Open /etc/sysconfig/memcached in a text editor.
    2. Locate the value for CACHESIZE and change it to at least 1GB.For example,
      CACHESIZE="1GB"
      
    3. Locate the value for OPTIONS and change it to localhost or 127.0.0.1

    For more information about configuring memcached, see the memcached wiki.

  2. Save your changes to memcached and exit the text editor.
  3. Restart memcached.
    service memcached restart
    
  4. Restart your web server.For Apache, service httpd restart
  5. Continue with the next section.

Verify memcached works before installing Magento

We recommend testing memcached to make sure it works before you install Magento. Doing so takes only a few minutes and can simplify troubleshooting later.

Verify memcached is recognized by the web server

To verify memcached is recognized by the web server:

    1. Create a phpinfo.php file in the web server’s docroot:
<?php
// Show all information, defaults to INFO_ALL
phpinfo();
  1. Go to that page in your web browser.For example, http://192.0.2.1/phpinfo.php
  2. Make sure memcache displays as follows:menVerify you’re using memcached version 3.0.5 or later.If memcache does not display, restart the web server and refresh the browser page. If it still does not display, verify you installed the php-pecl-memcache extension.

Create a memcache test consisting of a MySQL database and PHP script

The test uses a MySQL database, table, and data to verify you can retrieve the database data and store it in memcache. A PHP script first searches the cache. If the result does not exist, the script queries database. After the query has been fulfilled by the original database, the script stores the result in memcache, using the set command.

More details about this test

Create the MySQL database:

mysql -u root -p

At the mysql prompt, enter the following commands:

create database memcache_test;
GRANT ALL ON memcache_test.* TO memcache_test@localhost IDENTIFIED BY 'memcache_test';
use memcache_test;
create table example (id int, name varchar(30));
insert into example values (1, "new_data");
exit

Create cache-test.php in your web server’s docroot:

<?php
$meminstance = new Memcache();
$meminstance->pconnect('<memcache host name or ip>', <memcache port>);

mysql_connect("localhost", "memcache_test", "memcache_test") or die(mysql_error());
mysql_select_db("memcache_test") or die(mysql_error());

$query = "select id from example where name = 'new_data'";
$querykey = "KEY" . md5($query);

$result = $meminstance->get($querykey);

if (!$result) {
   $result = mysql_fetch_array(mysql_query("select id from example where name = 'new_data'")) or die('mysql error');
   $meminstance->set($querykey, $result, 0, 600);
   print "got result from mysql\n";
   return 0;
}
print "got result from memcached\n";
return 0;

?>

where <memcache host name or ip> is either localhost, 127.0.0.1, or the memcache host name or IP address. <memcache port> is its listen port; by default, 11211.

Run the script from the command line.

cd <web server docroot>
php cache-test.php

The first result is got result from mysql. This means that the key didn’t exist in memcache but it was retrieved from MySQL.

The second result is got result from memcached, which verifies that the value is stored successfully in memcache.

Finally, you can view the memcache keys using Telnet:

telnet localhost <memcache port>

At the prompt, enter

stats items

The result is similar to the following:

STAT items:3:number 1
STAT items:3:age 1075
STAT items:3:evicted 0
STAT items:3:evicted_nonzero 0
STAT items:3:evicted_time 0
STAT items:3:outofmemory 0
STAT items:3:tailrepairs 0

Flush the memcache storage and quit Telnet:

flush_all
quit

Additional information about the Telnet test

转载请注明:(●--●) Hello.My Weicot » CentOS 7* PHP memcache 和 memcached 扩展 以及其他扩展

蜀ICP备15020253号-1