安装步骤

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. wed.xml 中 filter、servlet 配置格式

    1.wed.xml 中 filter 配置格式 <filter> <filter-name>filterName</filter-name> <filter- ...

  2. BZOJ 4417 Luogu P3990 [SHOI2013]超级跳马 (DP、矩阵乘法)

    题目链接: (bzoj) https://www.lydsy.com/JudgeOnline/problem.php?id=4417 (luogu)https://www.luogu.org/prob ...

  3. Spring Boot教程(十八)构建RESTful API

    首先,回顾并详细说明一下在快速入门中使用的@Controller.@RestController.@RequestMapping注解.如果您对Spring MVC不熟悉并且还没有尝试过快速入门案例,建 ...

  4. Spring容器的基本使用

    1)如何将一个Bean组件交给Spring容器 方法:在applicationContext.xml中添加以下定义 <bean id = “标识符” class = “Bean组件类型”> ...

  5. listen( ) accept( )

    服务器端,创建socket,bind绑定套接字后,还需要使用listen()函数让套接字进入被动监听状态,再调用accept()函数,就可以随时响应客户端的请求了 listen() 函数 通过 lis ...

  6. 2014过去了,正式步入职场了,.net

    一.第一家公司(北京XXXXXXX) 从2014年7月1号拿到学位证,到7月15号到北京,努力找工作,用了两个多礼拜,终于找到了一个只有三个人的公司,愿意要我,薪资是实习三千,转正四千. 2014年7 ...

  7. leetcode 287寻找重复数

    这道题用STL容器就很好写了,可以用set也可以用map, 用unordered_map的C++代码如下: class Solution { public: int findDuplicate(vec ...

  8. Python Module_openpyxl_处理Excel表格

    目录 目录 前言 软件系统 Install openpyxl module Sample code load_workbook加载Excel文件 wbObjectget_sheet_names 获取E ...

  9. Python学习之==>模块结构调整

    一.为什么要进行模块结构调整 当一个脚本中有大量的配置.方法及接口时,脚本显得十分臃肿,可读性很差.为了提高代码的易读性,可以将一个繁杂的脚本根据不同的功能放在不同的目录下分类管理,这整个过程叫做模块 ...

  10. django连接和游标

    连接和游标主要实现 PEP 249中描述的Python DB API标准——除非它涉及到事务处理. 如果你不熟悉Python DB-API,注意cursor.execute()中的SQL语句使用占位符 ...