centos安装memcached和PHP php-pecl-memcached.x86_64

服务器

浏览数:242

2019-6-18

安装memcached

sudo yum install memcached.x86_64

安装php-pecl-memcached

php memcache有两个实现类

php-pecl-memcache.x86_64 : Extension to work with the Memcached caching daemon
php-pecl-memcached.x86_64 : Extension to work with the Memcached caching daemon

我们需要装

sudo yum install php-pecl-memcached.x86_64

否则,在PHP中会报错

Fatal error: Class ‘Memcache’ not found

启动memcached并测试php

sudo service memcached stop
sudo service memcached start

新建php-mem.php

<?php
$mem = new Memcache;
$mem->connect("localhost", 11211);
$mem->set('ryan', 'Miao', 0, 60);
$ryan = $mem->get('ryan');
echo $ryan;
?>

执行

php php-memcache.php 
Miao

作者:Ryan.Miao