php libredis,PHP-Redis长连接 f_redis_get_connected

PHP-Redis长连接 f_redis_get_connected

redis: get test

依赖

初始化

下载PHP7源码ext

cd ext

编辑文件 f_redis_get_connected.def 内容如src/f_redis_get_connected.def

vim f_redis_get_connected.def

./ext_skel --extname=f_redis_get_connected --proto=f_redis_get_connected.def

编译配置

cd f_redis_get_connected

vim config.m4

去掉 PHP_ARG_WITH 和 [ --with-f_redis_get_connected 前面的dnl 在文件底部添加下面两行,内容如src/config.m4

PHP_ADD_LIBRARY_WITH_PATH(hiredis, /usr/local/lib/, F_REDIS_GET_CONNECTED_SHARED_LIBADD)

PHP_SUBST(F_REDIS_GET_CONNECTED_SHARED_LIBADD)

功能实现

实现函数 PHP_FUNCTION(f_redis_get_connected) 代码如 src/f_redis_get_connected.c

vim f_redis_get_connected.c

添加配置

1、php_f_redis_get_connected.h中添加如下内容

ZEND_BEGIN_MODULE_GLOBALS(f_redis_get_connected)

zend_long redis_port;

char *redis_host;

ZEND_END_MODULE_GLOBALS(f_redis_get_connected)

2、f_redis_get_connected.c中添加如下内容

ZEND_DECLARE_MODULE_GLOBALS(f_redis_get_connected)

PHP_INI_BEGIN()

STD_PHP_INI_ENTRY("f_redis_get_connected.redis_port", "6379", PHP_INI_ALL, OnUpdateLong, redis_port, zend_f_redis_get_connected_globals, f_redis_get_connected_globals)

STD_PHP_INI_ENTRY("f_redis_get_connected.redis_host", "127.0.0.1", PHP_INI_ALL, OnUpdateString, redis_host, zend_f_redis_get_connected_globals, f_redis_get_connected_globals)

PHP_INI_END()

3、php.ini中添加如下内容

extension=f_redis_get_connected.so

;;;;;;;;;;;;;;;;;;;

; Module Settings ;

;;;;;;;;;;;;;;;;;;;

[F_redis_get_connected]

f_redis_get_connected.redis_host = "127.0.0.1"

f_redis_get_connected.redis_port = 6379

4、f_redis_get_connected.c中获取配置方法如下

F_REDIS_GET_CONNECTED_G(redis_host)

编译、安装

PHP7/bin/phpize

./configure --with-php-config=PHP7/bin/php-config

./make && make install

运行PHP

print_r(f_redis_get_connected('0', 'test'));

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值