>백엔드 개발 >PHP 튜토리얼 >phpredis 扩展安装

phpredis 扩展安装

WBOY
WBOY원래의
2016-06-06 20:27:071480검색

一 下载:git上下载redis的扩展包

git clone https://github.com/nicolasff/phpredis

二 挂载:在shell中输入 phpize 【查看适合的版本信息】

<code> ./configure 编译</code>

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

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

<code>cuihuan:phpredis cuixiaohuan$ phpize
Configuring for:
PHP Api Version:         20121113
Zend Module Api No:      20121212
Zend Extension Api No:   220121212
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
</code>

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

<code>[work@cuixiaozhuai phpredis]$ phpize        
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20060613
Zend Extension Api No:   220060519
[work@cuixiaozhuai phpredis]$ ./configure
</code>

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

<code> ./configure --with-php-config=/home/work/thirdparty/php5/bin/php-config 
</code>

三 安装: make 之后make test 最好 make install

<code>Build complete.
Don't forget to run 'make test'.

cuihuan:phpredis cuixiaohuan$ make test
</code>

四 问题报错修复:【已修复,但是原因可能不太准确】

make编译报错

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

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

<code>  40 

  41 /* Argument info for HSCAN, SSCAN, HSCAN */

  42 /*ZEND_BEGIN_ARG_INFO_EX(arginfo_kscan, 0, 0, 2)

  43     ZEND_ARG_INFO(0, str_key)

  44     ZEND_ARG_INFO(1, i_iterator)

  45     ZEND_ARG_INFO(0, str_pattern)

  46     ZEND_ARG_INFO(0, i_count)

  47 ZEND_END_ARG_INFO();

  48 */

  49 

  50 /* Argument infor for SCAN */

  51 /*

  52 ZEND_BEGIN_ARG_INFO_EX(arginfo_scan, 0, 0, 2)

  53     ZEND_ARG_INFO(1, i_iterator)

  54     ZEND_ARG_INFO(0, str_node)

  55     ZEND_ARG_INFO(0, str_pattern)

  56     ZEND_ARG_INFO(0, i_count)

  57 ZEND_END_ARG_INFO();

  58 */
  
  </code>

五 进行简单的php操作测试

<code><?php $redis = new Redis();
    $conn = $redis->connect('127.0.0.1',6379);

    echo "redis pass and status show";
    var_dump($redis->ping());

    $redis->set('test_key','test_value');
    echo "test set val=".$redis->get('test_key')."";

    $redis->setnx('unique_key',"unique_val");
    $redis->setnx('unique_key',"unique_val_2");

    echo $redis->get("unique_key");

    sleep(60);
    echo 'is exist'.$redis->exists('test_60s');
    echo 'not has value'.$redis->get('test_60s');
    $redis->delete('test_key','test_60s');</code>

回复内容:

一 下载:git上下载redis的扩展包

git clone https://github.com/nicolasff/phpredis

二 挂载:在shell中输入 phpize 【查看适合的版本信息】

<code> ./configure 编译</code>

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

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

<code>cuihuan:phpredis cuixiaohuan$ phpize
Configuring for:
PHP Api Version:         20121113
Zend Module Api No:      20121212
Zend Extension Api No:   220121212
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
</code>

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

<code>[work@cuixiaozhuai phpredis]$ phpize        
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20060613
Zend Extension Api No:   220060519
[work@cuixiaozhuai phpredis]$ ./configure
</code>

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

<code> ./configure --with-php-config=/home/work/thirdparty/php5/bin/php-config 
</code>

三 安装: make 之后make test 最好 make install

<code>Build complete.
Don't forget to run 'make test'.

cuihuan:phpredis cuixiaohuan$ make test
</code>

四 问题报错修复:【已修复,但是原因可能不太准确】

make编译报错

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

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

<code>  40 

  41 /* Argument info for HSCAN, SSCAN, HSCAN */

  42 /*ZEND_BEGIN_ARG_INFO_EX(arginfo_kscan, 0, 0, 2)

  43     ZEND_ARG_INFO(0, str_key)

  44     ZEND_ARG_INFO(1, i_iterator)

  45     ZEND_ARG_INFO(0, str_pattern)

  46     ZEND_ARG_INFO(0, i_count)

  47 ZEND_END_ARG_INFO();

  48 */

  49 

  50 /* Argument infor for SCAN */

  51 /*

  52 ZEND_BEGIN_ARG_INFO_EX(arginfo_scan, 0, 0, 2)

  53     ZEND_ARG_INFO(1, i_iterator)

  54     ZEND_ARG_INFO(0, str_node)

  55     ZEND_ARG_INFO(0, str_pattern)

  56     ZEND_ARG_INFO(0, i_count)

  57 ZEND_END_ARG_INFO();

  58 */
  
  </code>

五 进行简单的php操作测试

<code><?php $redis = new Redis();
    $conn = $redis->connect('127.0.0.1',6379);

    echo "redis pass and status show";
    var_dump($redis->ping());

    $redis->set('test_key','test_value');
    echo "test set val=".$redis->get('test_key')."";

    $redis->setnx('unique_key',"unique_val");
    $redis->setnx('unique_key',"unique_val_2");

    echo $redis->get("unique_key");

    sleep(60);
    echo 'is exist'.$redis->exists('test_60s');
    echo 'not has value'.$redis->get('test_60s');
    $redis->delete('test_key','test_60s');</code>
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.