背景:在CenOS7.7下
1 編譯、安裝、測試
# 安裝依賴包 yum -y install cyrus-sasl-devel # 編譯安裝libmemcached tar -zxvf libmemcached-1.0.18.tar.gz cd libmemcached-1.0.18 ./configure && make && make install && cd .. # 為PHP的Memcached擴展生成configure文件 tar -zxvf memcached-2.2.0.tgz (我實際使用了 memcached-3.1.5版本) cd memcached-2.2.0 /usr/local/php/bin/phpize # 編譯安裝PHP的Memcached擴展 ./configure --with-php-config=/usr/local/php/bin/php-config make && make install && cd .. # 在PHP的配置文件php.ini中加載Memcached擴展 vi /usr/local/php/lib/php.ini # 添加如下配置 extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/memcached.so # PHP-FPM重新加載配置 service php-fpm reload # 測試Memcached vi /data/www/test.php <?php # 連接Memcached服務器 $mem = new Memcached(); $mem->addServer('192.168.78.19', 11211); # 保存數(shù)據(jù)(Key/Value形式,Key=UserName,Value=James) $mem->set('UserName', 'James'); # 獲取數(shù)據(jù)(根據(jù)Key=UserName,獲得Value)輸出結果:James echo $mem->get('UserName'); ?>
2 出現(xiàn)的問題
2.1 編譯libmemcached(./configure)時報錯
報錯內容如下:
clients/memflush.cc:42:22: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] if (opt_servers == false) ^~~~~ clients/memflush.cc:51:24: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] if (opt_servers == false) ^~~~~
原因:gcc版本比較高,不兼容。
解決方法:對源碼略作修改。
# 將clients/memflush.cc的42行和51行作如下修改: int main(int argc, char *argv[]) { options_parse(argc, argv); - if (opt_servers == false) + if (!opt_servers) { char *temp; - if (opt_servers == false) + if (!opt_servers) { std::cerr << "No Servers provided" << std::endl; exit(EXIT_FAILURE);
然后再次make,編譯通過。
2.2 編譯memcached-3.1.5報錯
報錯內容如下:
configure: error: no, libmemcached built with sasl disabled. Run configure with --disable-memcached-sasl or update libmemcached with sasl support
添加--disable-memcached-sasl,再次編譯通過:
./configure --with-php-config=/usr/local/php/bin/php-config --disable-memcached-sasl
版權聲明:文章圖片資源來源于網(wǎng)絡,如有侵權,請留言刪除!!!
評論