Heim  >  Artikel  >  Backend-Entwicklung  >  【redis学习二】多php版本下phpredis扩展安装

【redis学习二】多php版本下phpredis扩展安装

WBOY
WBOYOriginal
2016-07-23 08:54:441292Durchsuche

背景:安装完redis之后,需要安装phpredis扩展,才能让php操作redis;本机有多个php版本,安装过程中遇到的坑分享一下。

一 下载

git上下载redis的扩展包

  1. git clone https://github.com/nicolasff/phpredis
复制代码
二 挂载和configure

在shell中输入 phpize 【注意:多个php版本的时候需要指定】

  1. ./configure
复制代码

【phpize是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块】

注意:(phpize 如果包含多个php,必须指定位置)

  1. cuihuan:phpredis cuixiaohuan$ ../php/bin/phpize
  2. Configuring for:
  3. PHP Api Version: 20121113
  4. Zend Module Api No: 20121212
  5. Zend Extension Api No: 220121212
  6. Cannot find autoconf. Please check your autoconf installation and the
  7. $PHP_AUTOCONF environment variable. Then, rerun this script.
复制代码

报错的话需要安装:brew install autoconf [phpize 报错] 否则没有phpize

  1. [work@cuixiaozhuai phpredis]$ ../php/bin/phpize
  2. Configuring for:
  3. PHP Api Version: 20041225
  4. Zend Module Api No: 20060613
  5. Zend Extension Api No: 220060519
  6. [work@cuixiaozhuai phpredis]$ ./configure --with-php-config=/home/work/thirdparty/php5/bin/php-config
复制代码

当存在多个版本的php的时候,需要指定配置文件

  1. ./configure --with-php-config=/home/work/thirdparty/php5/bin/php-config
复制代码
三 编译和安装

make 之后最好make test
make install

  1. cuihuan:phpredis cuixiaohuan$ make
  2. 。。。
  3. Build complete.
  4. Don't forget to run 'make test'.
  5. cuihuan:phpredis cuixiaohuan$ make test
  6. cuihuan:phpredis cuixiaohuan$ make install
复制代码
四 问题修复

【已修复,但是原因可能不太准确】
make编译报错

  1. .libs/redis_cluster.o(.data.rel.local+0x0): In function `ht_free_seed':
  2. /home/work/thirdparty/php5/php5/phpredis/redis_cluster.c:226: multiple definition of `arginfo_scan'
  3. .libs/redis.o(.data.rel.local+0xe0):/home/work/thirdparty/php5/php5/p hpredis/redis.c:452: first defined here
  4. /usr/bin/ld: Warning: size of symbol `arginfo_scan' changed from 160 in .libs/redis.o to 200 in .libs/redis_cluster.o
  5. .libs/redis_cluster.o(.data.rel.local+0xe0): In function `create_cluster_context':
  6. /home/work/thirdparty/php5/php5/phpredis/redis_cluster.c:276: multiple definition of `arginfo_kscan'
  7. .libs/redis.o(.data.rel.local+0x0):/home/work/thirdparty/php5/php5/phpredis/redis.c:364: first defined here
  8. collect2: ld returned 1 exit status
  9. make: *** [redis.la] Error 1
复制代码

最初以为是php多个版本生成install问题,采用./configure 指定php版本,指定php位置。
但是效果还是有问题。
最终通过修改redis_cluester.c 中,注释掉了这两个重复的

  1. 40
  2. 41 /* Argument info for HSCAN, SSCAN, HSCAN */
  3. 42 /*ZEND_BEGIN_ARG_INFO_EX(arginfo_kscan, 0, 0, 2)
  4. 43 ZEND_ARG_INFO(0, str_key)
  5. 44 ZEND_ARG_INFO(1, i_iterator)
  6. 45 ZEND_ARG_INFO(0, str_pattern)
  7. 46 ZEND_ARG_INFO(0, i_count)
  8. 47 ZEND_END_ARG_INFO();
  9. 48 */
  10. 49
  11. 50 /* Argument infor for SCAN */
  12. 51 /*
  13. 52 ZEND_BEGIN_ARG_INFO_EX(arginfo_scan, 0, 0, 2)
  14. 53 ZEND_ARG_INFO(1, i_iterator)
  15. 54 ZEND_ARG_INFO(0, str_node)
  16. 55 ZEND_ARG_INFO(0, str_pattern)
  17. 56 ZEND_ARG_INFO(0, i_count)
  18. 57 ZEND_END_ARG_INFO();
  19. 58 */
复制代码
五 简单测试
  1. $redis = new Redis();
  2. $conn = $redis->connect('127.0.0.1',6379);
  3. echo "redis pass and status show";
  4. var_dump($redis->ping());
  5. $redis->set('test_key','test_value');
  6. echo "test set val=".$redis->get('test_key')."";
  7. $redis->setnx('unique_key',"unique_val");
  8. $redis->setnx('unique_key',"unique_val_2");
  9. echo $redis->get("unique_key");
  10. sleep(60);
  11. echo 'is exist'.$redis->exists('test_60s');
  12. echo 'not has value'.$redis->get('test_60s');
  13. $redis->delete('test_key','test_60s');
复制代码

个人小站原文链接

redis, php, phpredis


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:PHP PSR-2 代码风格规范 Nächster Artikel:PHP PSR-1 基本代码规范