安装步骤

php-zookeeper依赖libzookeeper,所以需要先安装libzookeeper

安装libzookeeper
cd /usr/local/src/

wget http://mirror.bit.edu.cn/apache/zookeeper/stable/zookeeper-3.4.12.tar.gz

tar -xf zookeeper-3.4.12.tar.gz

cd zookeeper-3.4.12/src/c

./configure -prefix=/usr/local/zookeeper/zookeeper-3.4.12/

make && make install
安装php zookeeper扩展
cd /usr/local/src/

wget https://pecl.php.net/get/zookeeper-0.5.0.tgz

tar zxvf zookeeper-0.5.0.tgz

cd zookeeper-0.5.0

phpize

./configure –with-php-config=/usr/local/php/bin/php-config  –with-libzookeeper-dir=/usr/local/zookeeper/zookeeper-3.4.12/

make && make install

修改php.ini,新增extension=zookeeper.so,然后重启php
vim /usr/local/etc/php/7.0/php.ini
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
extension_dir = "/usr/local/lib/php/pecl/20151012"
; On windows:
; extension_dir = "ext" extension=zookeeper.so

遇到的问题

无论是安装libzookeeper还是安装php zookeeper扩展,在执行make && make install命令时会出现类似下面错误。网上查找了很大资料,都没这方面的解决方案,貌似只有在mac下才会有这样的问题。

/Library/Developer/CommandLineTools/usr/bin/make  all-am
/bin/sh ./libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I./include -I./tests -I./generated -Wall -Werror -g -O2 -D_GNU_SOURCE -MT zookeeper.lo -MD -MP -MF .deps/zookeeper.Tpo -c -o zookeeper.lo `test -f 'src/zookeeper.c' || echo './'`src/zookeeper.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I./include -I./tests -I./generated -Wall -Werror -g -O2 -D_GNU_SOURCE -MT zookeeper.lo -MD -MP -MF .deps/zookeeper.Tpo -c src/zookeeper.c -fno-common -DPIC -o .libs/zookeeper.o
In file included from src/zookeeper.c:37:
/usr/local/include/string.h:49:1: error: unknown type name 'HASHKIT_API'
HASHKIT_API
^
/usr/local/include/string.h:50:1: error: expected identifier or '('
void hashkit_string_free(hashkit_string_st *ptr);
^
/usr/local/include/string.h:53:1: error: unknown type name 'HASHKIT_API'
HASHKIT_API
^
/usr/local/include/string.h:54:7: error: expected ';' after top level declarator
size_t hashkit_string_length(const hashkit_string_st *self);
^
/usr/local/include/string.h:56:1: error: unknown type name 'HASHKIT_API'
HASHKIT_API
^
/usr/local/include/string.h:57:1: error: expected identifier or '('
const char *hashkit_string_c_str(const hashkit_string_st* self);
^
src/zookeeper.c:505:19: error: implicitly declaring library function 'strdup' with type 'char *(const char *)'
[-Werror,-Wimplicit-function-declaration]
char *hosts = strdup(zh->hostname);
^
src/zookeeper.c:505:19: note: include the header <string.h> or explicitly provide a declaration for 'strdup'
src/zookeeper.c:524:10: error: implicit declaration of function 'strtok_r' is invalid in C99
[-Werror,-Wimplicit-function-declaration]
host=strtok_r(hosts, ",", &strtok_last);
^
src/zookeeper.c:524:9: error: incompatible integer to pointer conversion assigning to 'char *' from 'int'
[-Werror,-Wint-conversion]
host=strtok_r(hosts, ",", &strtok_last);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/zookeeper.c:526:27: error: implicitly declaring library function 'strrchr' with type
'char *(const char *, int)' [-Werror,-Wimplicit-function-declaration]
char *port_spec = strrchr(host, ':');
^
src/zookeeper.c:526:27: note: include the header <string.h> or explicitly provide a declaration for 'strrchr'
src/zookeeper.c:604:9: error: implicitly declaring library function 'memset' with type
'void *(void *, int, unsigned long)' [-Werror,-Wimplicit-function-declaration]
memset(&hints, 0, sizeof(hints));
^
src/zookeeper.c:604:9: note: include the header <string.h> or explicitly provide a declaration for 'memset'
src/zookeeper.c:640:49: error: implicitly declaring library function 'strerror' with type 'char *(int)'
[-Werror,-Wimplicit-function-declaration]
LOG_ERROR(("getaddrinfo: %s\n", strerror(errno)));
^
src/zookeeper.c:640:49: note: include the header <string.h> or explicitly provide a declaration for 'strerror'
src/zookeeper.c:669:17: error: implicitly declaring library function 'memcpy' with type 'void *(void *, const
void *, unsigned long)' [-Werror,-Wimplicit-function-declaration]
memcpy(addr, res->ai_addr, res->ai_addrlen);
^
src/zookeeper.c:669:17: note: include the header <string.h> or explicitly provide a declaration for 'memcpy'
src/zookeeper.c:681:14: error: incompatible integer to pointer conversion assigning to 'char *' from 'int'
[-Werror,-Wint-conversion]
host = strtok_r(0, ",", &strtok_last);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/zookeeper.c:849:20: error: implicitly declaring library function 'strchr' with type
'char *(const char *, int)' [-Werror,-Wimplicit-function-declaration]
index_chroot = strchr(host, '/');
^
src/zookeeper.c:849:20: note: include the header <string.h> or explicitly provide a declaration for 'strchr'
src/zookeeper.c:856:13: error: implicitly declaring library function 'strlen' with type
'unsigned long (const char *)' [-Werror,-Wimplicit-function-declaration]
if (strlen(zh->chroot) == 1) {
^
src/zookeeper.c:856:13: note: include the header <string.h> or explicitly provide a declaration for 'strlen'
src/zookeeper.c:862:24: error: implicitly declaring library function 'strncpy' with type 'char *(char *, const
char *, unsigned long)' [-Werror,-Wimplicit-function-declaration]
zh->hostname = strncpy(zh->hostname, host, (index_chroot - host));
^
src/zookeeper.c:862:24: note: include the header <string.h> or explicitly provide a declaration for 'strncpy'
src/zookeeper.c:932:5: error: implicitly declaring library function 'strcpy' with type
'char *(char *, const char *)' [-Werror,-Wimplicit-function-declaration]
strcpy(ret_str, zh->chroot);
^
src/zookeeper.c:932:5: note: include the header <string.h> or explicitly provide a declaration for 'strcpy'
src/zookeeper.c:933:12: error: implicitly declaring library function 'strcat' with type
'char *(char *, const char *)' [-Werror,-Wimplicit-function-declaration]
return strcat(ret_str, client_path);
^
src/zookeeper.c:933:12: note: include the header <string.h> or explicitly provide a declaration for 'strcat'
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[1]: *** [zookeeper.lo] Error 1
make: *** [all] Error 2

解决方法

分析上面问题,基本是变量和一些string函数没有被显示声明。解决方法就是将没有定义的变量注释掉,将没有显示声明的函数补上。

重写/usr/local/include/string.h 文件如下,可以直接拷贝使用。然后重新执行make && make install,就可以了。

/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
*
* HashKit library
*
* Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/
* Copyright (C) 2009-2010 Brian Aker All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* * The names of its contributors may not be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/ #pragma once #ifdef __cplusplus
struct hashkit_string_st;
#endif #ifdef __cplusplus
extern "C" {
#endif
/*
HASHKIT_API
void hashkit_string_free(hashkit_string_st *ptr); HASHKIT_API
size_t hashkit_string_length(const hashkit_string_st *self); HASHKIT_API
const char *hashkit_string_c_str(const hashkit_string_st* self);
*/ char *strdup(const char *s); char *strtok_r(char *s, const char *delim, char **ptrptr); char *strrchr(const char *, int); void *memset(void *, int, unsigned long); char *strerror(int); void *memcpy(void *, const void *, unsigned long); char *strchr(const char *, int); unsigned long strlen(const char *); char *strncpy(char *, const char *, unsigned long); char *strcpy(char *, const char *); char *strcat(char *, const char *); int strncmp(const char *, const char *, unsigned long); int strcmp(const char *, const char *); void *memmove(void *, const void *, unsigned long); int memcmp(const void *, const void *, unsigned long); void *memchr(const void *, int, unsigned long); #ifdef __cplusplus
} // extern "C"
#endif

mac下安装php zookeeper扩展的更多相关文章

  1. Mac下安装HBase及详解

    Mac下安装HBase及详解 1. 千篇一律的HBase简介 HBase是Hadoop的数据库, 而Hive数据库的管理工具, HBase具有分布式, 可扩展及面向列存储的特点(基于谷歌BigTabl ...

  2. Mac 下安装Jenkins

    Mac 下安装Jenkins 开始 Jenkins是一个基于Java开发的一种持续集成工具,用于建工持续重复的工作,功能包括: 持续的软件版本发布/测试项目 监控外部调用执行的工作. 近期打算搭建自动 ...

  3. mac 下安装mongodb

    转载自https://segmentfault.com/a/1190000002547229 概念 MongoDB 是一个跨平台的,面向文档的数据库,提供高性能,高可用性和可扩展性方便. MongoD ...

  4. MAC下安装与配置MySQL

    MAC下安装与配置MySQL   MAC下安装与配置MySQL 一 下载MySQL 访问MySQL的官网http://www.mysql.com/downloads/ 然后在页面中会看到“MySQL ...

  5. Mac下安装UPnP Inspector

    由于工作中需要用到UPnP Inspector这个工具,而这个工具在windows下安装非常简单,在Mac下安装却很麻烦,在此记录安装流程. 这个工具依赖于两个其他的库:Coherence(一个DLN ...

  6. Mac下安装Wireshark,双击闪退

     Mac OS X上使用Wireshark抓包(http://blog.csdn.net/phunxm/article/details/38590561) Mac下安装Wireshark /Appli ...

  7. Mac下安装zshell

    Mac 下安装zshell 什么是shell 大多数命令行用户接触最多的是Bash,因为Bash是各个版本操作系统(Linux&Mac)的默认shell. 查看当前使用的shell $ ech ...

  8. 【高可用HA】Apache (1) —— Mac下安装Apache Httpd到自定义路径(非/etc/apache2)

    Mac下安装Apache Httpd httpd版本: httpd-2.4.17 参考来源: Tomcat Clustering - A Step By Step Guide Apache HTTP ...

  9. 《OD大数据实战》mac下安装nginx+php

    一.mac安装nginx + php + php-fpm  或apache + php 1. Mac 下 Nginx.MySQL.PHP-FPM 的安装配置 2. Mac下安装LNMP(Nginx+P ...

随机推荐

  1. 定时器的写法 winform

    private void timer1_Tick(object sender, EventArgs e) { if ( tttttflag) { Action action = SyncCompany ...

  2. linux 系统下 zip 的加密压缩与解压缩命令

    1.加密压缩 [small@sun shine]# zip -rP king java.zip java adding: java/ (stored 0%) adding: java/default/ ...

  3. navicat安装与激活

    原文网址:https://www.jianshu.com/p/5f693b4c9468?mType=Group 一.Navicat Premium 12下载 Navicat Premium 12是一套 ...

  4. 【Leetcode】整数反转

    题解参考:https://leetcode-cn.com/problems/reverse-integer/solution/zheng-shu-fan-zhuan-by-leetcode/ 复杂度分 ...

  5. yield return的使用。。。

    因为要取两个集合不同的元素,所以写了个拓展方法,用到了yield这个关键字,然后就学习了一波.先上代码 public static IEnumerable<T> NoRetainAll&l ...

  6. [design pattern](4) SImple Factory

    前言 本博客主要介绍简单工厂模式(Simple Factory),简单工厂模式是创建型模式的一员,也是我们平时coding用到的比较多的一个模式了. 思考题 首先,让我们思考以下的需求: 博主,突然很 ...

  7. jvm内存模型学习心得

    昨天面试了两家,备受打击,问的多的就是jvm内存,然额真的是一头雾水.工作中用到的真是少之又少,面试还得问道, 今天恶补了下,在此作以下总结: jvm分为5部分 1.程序计数器 jvm支持多线程运行, ...

  8. 数据结构和算法(Java版)快速学习(线性表)

    线性表的基本特征: 第一个数据元素没有前驱元素: 最后一个数据元素没有后继元素: 其余每个数据元素只有一个前驱元素和一个后继元素. 线性表按物理存储结构的不同可分为顺序表(顺序存储)和链表(链式存储) ...

  9. oracle ogg 单实例双向-新增表,修改表结构(oracle-oracle

    --新增inset测试--dept 表结构orcl,ogg都存在,数据相同(但是rep1配置文件没有添加) SCOTT@ orcl ,'hongquan','BBA'); row created. S ...

  10. 正则表达式——Unicode

    第 7 章 Unicode 7.1 关于编码   通常,英文编码较为统一,都采用ASCII编码或可以兼容ASCII编码(即编码表的前127位与ASCII编码一直,常见的各种编码,包括Unicode编码 ...